Commit b39281ef authored by Thomas Löffler's avatar Thomas Löffler

Removes unused functions, methods and templates

parent 5ecb851d
Pipeline #2267 passed with stages
in 1 minute and 27 seconds
<?php
namespace T3o\TerFe2\Cache;
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Cache for extension files
*/
class FileCache implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* @var string
*/
protected $cacheDirectory;
/**
* Set cache directory path
*
* @param string $cacheDirectory Path to cache directory
* @return void
*/
public function setCacheDirectory($cacheDirectory)
{
if (empty($cacheDirectory)) {
throw new \Exception('An empty cache directory is not allowed');
}
$this->cacheDirectory = \T3o\TerFe2\Utility\File::getAbsoluteDirectory($cacheDirectory);
}
/**
* Get cache directory path
*
* @return string Path of the cache directory
*/
public function getCacheDirectory()
{
return $this->cacheDirectory;
}
/**
* Get filename
*
* @param string $filename Name of the file
* @return string Local filename
*/
public function getFile($filename)
{
$filename = $this->getFilePath($filename);
if (\T3o\TerFe2\Utility\File::fileExists($filename)) {
return $filename;
}
return '';
}
/**
* Returns an extension related filename
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Local filename
*/
public function getExtensionFile($extensionKey, $filename)
{
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->getFile($filename);
}
/**
* Copy a file to local cache
*
* @param string $fileUrl Url to the file
* @param string $filename Name of the file
* @return string Local filename
*/
public function addFile($fileUrl, $filename)
{
if (empty($fileUrl)) {
return '';
}
$filename = $this->getFilePath($filename);
if (\T3o\TerFe2\Utility\File::copyFile($fileUrl, $filename)) {
return $filename;
}
return '';
}
/**
* Copy an extension file to local cache
*
* @param string $extensionKey Extension key
* @param string $fileUrl Url to the file
* @param string $filename Name of the file
* @return string Local filename
*/
public function addExtensionFile($extensionKey, $fileUrl, $filename)
{
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->addFile($fileUrl, $filename);
}
/**
* Remove a file from local cache
*
* @param string $filename Name of the file
* @return boolean TRUE if success
*/
public function removeFile($filename)
{
$filename = $this->getFilePath($filename);
if (!\T3o\TerFe2\Utility\File::fileExists($fileUrl)) {
return false;
}
return unlink($filename);
}
/**
* Remove an extension file from local cache
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Local filename
*/
public function removeExtensionFile($extensionKey, $filename)
{
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->removeFile($filename);
}
/**
* Returns the filename of a file
*
* @param string $filename Name of the file
* @return string Absolute path to file
*/
protected function getFilePath($filename)
{
if (empty($filename)) {
return '';
}
$cacheDirectory = $this->getCacheDirectory();
if (empty($cacheDirectory)) {
throw new \Exception('No cache directory defined');
}
return $cacheDirectory . $filename;
}
/**
* Returns the filename of an extension file
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Extension filename
*/
protected function getExtensionFilename($extensionKey, $filename)
{
if (empty($extensionKey) || empty($filename)) {
return '';
}
return strtolower($extensionKey) . '/' . basename($filename);
}
}
<?php
namespace T3o\TerFe2\Controller;
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Controller for the author object
*/
class AuthorController extends \T3o\TerFe2\Controller\AbstractController
{
/**
* @var \T3o\TerFe2\Domain\Repository\AuthorRepository
*/
protected $authorRepository;
/**
* @var \T3o\TerFe2\Domain\Repository\ExtensionRepository
*/
protected $extensionRepository;
/**
* Initializes the controller
*
* @return void
*/
protected function initializeController()
{
$this->authorRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\AuthorRepository::class);
$this->extensionRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\ExtensionRepository::class);
}
/**
* List action, displays all authors
*
* @return void
*/
public function listAction()
{
$this->view->assign('authors', $this->authorRepository->findAll());
}
/**
* Action that displays a single author
*
* @param \T3o\TerFe2\Domain\Model\Author $author The author to display
* @return void
*/
public function showAction(\T3o\TerFe2\Domain\Model\Author $author)
{
$this->view->assign('author', $author);
$authorExtensions = $this->extensionRepository->findByAuthor($author);
$this->view->assign('authorExtensions', $authorExtensions);
}
/**
* Displays a form to edit an existing author
*
* @param \T3o\TerFe2\Domain\Model\Author $author The author to display
* @return void
* @dontvalidate $author
*/
public function editAction(\T3o\TerFe2\Domain\Model\Author $author)
{
$this->view->assign('author', $author);
}
/**
* Updates an existing author
*
* @param \T3o\TerFe2\Domain\Model\Author $author Author to update
* @return void
*/
public function updateAction(\T3o\TerFe2\Domain\Model\Author $author)
{
$this->authorRepository->update($author);
$this->redirectWithMessage($this->translate('msg.author_updated'), 'list');
}
}
......@@ -41,11 +41,6 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
*/
protected $tagRepository;
/**
* @var \T3o\TerFe2\Domain\Repository\AuthorRepository
*/
protected $authorRepository;
/**
* @var \T3o\TerFe2\Domain\Repository\VersionRepository
*/
......@@ -86,7 +81,6 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
$this->extensionRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\ExtensionRepository::class);
$this->tagRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\TagRepository::class);
$this->versionRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\VersionRepository::class);
$this->authorRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\AuthorRepository::class);
$this->ownerRepository = $this->objectManager->get(\TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository::class);
$querySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
$querySettings->setRespectStoragePage(false);
......@@ -102,63 +96,6 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
$this->frontendUser = (!empty($GLOBALS['TSFE']->fe_user->user) ? $GLOBALS['TSFE']->fe_user->user : array());
}
/**
* Index action, displays extension list (USER)
*
* @return void
* @dontvalidate $search
*/
public function indexAction()
{
$this->searchAction();
}
/**
* search action (USER_INT)
*
* @param array $search Search params for extension list
* @param array $restoreSearch Restore last search from session
* @return void
* @dontvalidate $search
*/
public function searchAction(array $search = array(), $restoreSearch = false)
{
// Get extension list
if (!empty($this->settings['show']['extensionSearch'])) {
$this->view->assign('extensions', $this->getExtensions($search, $restoreSearch));
$this->view->assign('search', $search);
} else {
$this->view->assign('extensions', $this->extensionRepository->findAll());
}
// Get all tags
if (!empty($this->settings['show']['tagOverview'])) {
$tags = $this->tagRepository->findAll();
$this->view->assign('tags', $tags);
}
// Get authors
if (!empty($this->settings['show']['authorOverview'])) {
$authors = $this->authorRepository->findByLatestExtensionVersion();
$this->view->assign('authors', $authors);
}
}
/**
* List action, displays all extensions
*
* Note: Required for RSS / JSON output
*
* @return void
*/
public function listAction()
{
$this->view->assign('extensions', $this->extensionRepository->findAll());
}
/**
* List latest action, displays new and updated extensions
*
......@@ -262,34 +199,6 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
}
}
/**
* Displays a form for creating a new extension
*
* @param \T3o\TerFe2\Domain\Model\Extension $newExtension New extension object
* @return void
* @dontvalidate $newExtension
*/
public function newAction(\T3o\TerFe2\Domain\Model\Extension $newExtension = null)
{
$this->view->assign('newExtension', $newExtension);
$this->view->assign('tags', $this->tagRepository->findAll());
}
/**
* Creates a new extension
*
* @param \T3o\TerFe2\Domain\Model\Extension $newExtension New extension object
* @return void
*/
public function createAction(\T3o\TerFe2\Domain\Model\Extension $newExtension)
{
$this->extensionRepository->add($newExtension);
$this->redirectWithMessage($this->translate('msg.extension_created'), 'index');
}
/**
* Displays a form to edit an existing extension
*
......@@ -584,96 +493,6 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
$this->forwardWithError($this->translate('msg.createVersionUploadFailed'), 'uploadVersion');
}
/**
* Returns all / filtered extensions
*
* @param array $options Options for extension list
* @param array $restoreSearch Restore last search from session
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage Objects
*/
protected function getExtensions(array &$options, $restoreSearch = false)
{
// Get last search
$session = $this->objectManager->get(\T3o\TerFe2\Persistence\Session::class);
$lastSearch = $session->get('lastSearch');
// Revert last search if set
if (!empty($restoreSearch) && !empty($lastSearch)) {
$options = $lastSearch;
}
// Direction
$desc = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
$asc = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
$direction = $desc;
if (!empty($options['direction'])) {
$direction = ($options['direction'] === 'asc' ? $asc : $desc);
}
// Sorting
$sortings = array(
'updated' => 'lastVersion.uploadDate',
'downloads' => 'downloads',
'title' => 'lastVersion.title',
);
$sorting = $sortings['updated'];
if (!empty($options['sorting'])) {
// Set direction to ASC when sorting by title
if (!empty($sortings[$options['sorting']])) {
$sorting = $sortings[$options['sorting']];
if (empty($options['direction'])) {
$direction = $desc;
if ($options['sorting'] === 'title') {
$direction = $asc;
$options['direction'] = 'asc';
}
}
}
// Sort by downloads when searching
if (!empty($options['needle']) && (empty($lastSearch['needle']) || $lastSearch['needle'] !== $options['needle'])) {
$sorting = $sortings['downloads'];
$options['sorting'] = 'downloads';
$direction = $desc;
}
}
// Set new search params
$searchParams = array();
if (!empty($options['needle'])) {
$searchParams = array(
'needle' => $options['needle'],
'sorting' => $sorting,
'direction' => $direction,
);
}
$session->set('lastSearch', $searchParams);
// Ordering
$ordering = array($sorting => $direction);
// Return sorted list of all extensions
if (empty($options['needle'])) {
return $this->extensionRepository->findAll(0, 0, $ordering);
}
// Return search result
return $this->extensionRepository->findBySearchWordsAndFilters($options['needle'], array(), $ordering);
}
/**
* gets the number of extensions in TER (for ajax call)
*
* @return int $number of extensions
*/
public function getExtensionNumberAction()
{
$number = $this->extensionRepository->findAll()->count();
return (int)$number;
}
/**
* Check if current frontend user can upload given extension
*
......
......@@ -151,203 +151,6 @@ class RegisterkeyController extends \T3o\TerFe2\Controller\AbstractTerBasedContr
$this->redirect('index', 'Registerkey', null, array());
}
/**
* an action to salvage the keys that were registered on the old TYPO3.org, but never had uploads
*
* @author Christian Zenker <christian.zenker@599media.de>
*/
public function salvageAction()
{
$error = null;
$registeredExtensions = $this->terConnection->getExtensionKeysByUser($error);
if ($error) {
$this->addFlashMessage(
$this->resolveWSErrorMessage($error),
'',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
} elseif (!is_array($registeredExtensions)) {
$this->addFlashMessage(
$this->resolveWSErrorMessage('result_empty.message'),
$this->resolveWSErrorMessage('result_empty.title'),
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
} elseif (empty($registeredExtensions)) {
$this->addFlashMessage(
$this->resolveWSErrorMessage('nothing_found'),
'',
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
);
} else {
$countSkipped = 0;
$countSalvaged = 0;
// get an array of the already existent extension keys
$existingExtensionKeys = $this->getExistingExtensionsByList($registeredExtensions);
foreach ($registeredExtensions as $extension) {
$extensionKey = $extension['extensionkey'];
if (in_array($extensionKey, $existingExtensionKeys)) {
// if: key already exists
// $this->addFlashMessage(
// sprintf('%s already exists.', $extensionKey),
// '',
// \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE
// );
$countSkipped++;
} else {
$extensionModel = $this->objectManager->get(\T3o\TerFe2\Domain\Model\Extension::class);
$extensionModel->setExtKey($extensionKey);
$extensionModel->setFrontendUser($extension['ownerusername']);
$this->extensionRepository->add($extensionModel);
// $this->addFlashMessage(
// '',
// sprintf('%s salvaged.', $extensionKey ),
// \TYPO3\CMS\Core\Messaging\FlashMessage::OK
// );
$countSalvaged++;
}
}
if ($countSalvaged > 0) {
$this->addFlashMessage(
$this->translate('registerkey.salvage.success', array($countSalvaged)),
'',
\TYPO3\CMS\Core\Messaging\FlashMessage::OK
);
} elseif ($countSkipped == 1) {
$this->addFlashMessage(
$this->translate('registerkey.salvage.pass1.message'),
$this->translate('registerkey.salvage.pass.title'),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
);
} elseif ($countSkipped > 1) {
$this->addFlashMessage(
$this->translate('registerkey.salvage.pass.message', array($countSkipped)),
$this->translate('registerkey.salvage.pass.title'),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
);
} else {
$this->addFlashMessage(
$this->resolveWSErrorMessage('nothing_found