Commit 01c279c9 authored by Thomas Löffler's avatar Thomas Löffler

[TASK] Remove obsolete scheduler tasks

parent 849abbeb
Pipeline #503 passed with stages
in 2 minutes and 37 seconds
<?php
/*******************************************************************
* 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!
******************************************************************/
/**
* Create zip archives from t3x files and generate images
*/
class Tx_TerFe2_Task_CreateExtensionFilesTask extends Tx_TerFe2_Task_AbstractTask
{
/**
* @var Tx_TerFe2_Domain_Repository_VersionRepository
*/
protected $versionRepository;
/**
* @var Tx_TerFe2_Provider_ProviderManager
*/
protected $providerManager;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
*/
protected $persistenceManager;
/**
* @var string
*/
protected $mediaRootPath = '';
/**
* @var array
*/
protected $imageSizes = array('small', 'large');
/**
* Initialize task
*
* @return void
*/
public function initializeTask()
{
$this->versionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_VersionRepository');
$this->providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$this->persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
if (empty($this->setup['settings.']['mediaRootPath'])) {
throw new Exception('Please configure "plugin.tx_terfe2.settings.mediaRootPath" in TypoScript setup');
}
$this->mediaRootPath = $this->setup['settings.']['mediaRootPath'];
}
/**
* Execute the task
*
* @param integer $lastRun Timestamp of the last run
* @param integer $offset Starting point
* @param integer $count Element count to process at once
* @return boolean TRUE on success
*/
protected function executeTask($lastRun, $offset, $count)
{
// Get all unprocessed versions
$versions = $this->versionRepository->findForMediaCreation($offset, $count);
if ($versions->count() === 0) {
return FALSE;
}
// Simulate working directory "htdocs", required for file_exists check
// in \TYPO3\CMS\Core\Imaging\GraphicalFunctions::getImageDimensions
$currentDir = getcwd();
chdir(PATH_site);
// Create ZIP file only for last version
$lastVersionOnly = !empty($this->setup['settings.']['onlyLatestVersionZip']);
foreach ($versions as $version) {
// Get media path for the extension
$extKey = $version->getExtension()->getExtKey();
$lastVersion = $version->getExtension()->getLastVersion();
$extensionMediaPath = Tx_TerFe2_Utility_File::getAbsoluteDirectory($this->mediaRootPath . $extKey);
// Create zip file
if (!$lastVersionOnly || ($lastVersion === $version)) {
$zipFile = $this->createZipFile($version, $extensionMediaPath);
if (!empty($zipFile)) {
$version->setZipFileSize(filesize($zipFile));
$version->setHasZipFile(TRUE);
}
}
// Create images
if ($this->createImages($version, $extensionMediaPath)) {
$version->setHasImages(TRUE);
}
$this->persistenceManager->persistAll();
}
// Revert working directory
chdir($currentDir);
return TRUE;
}
/**
* Create a zip file for given version
*
* @param Tx_TerFe2_Domain_Model_Version $version Path to t3x file
* @param string $extensionMediaPath Path to media files
* @return string Name of the zip file
*/
protected function createZipFile(Tx_TerFe2_Domain_Model_Version $version, $extensionMediaPath)
{
if (empty($extensionMediaPath)) {
return '';
}
$provider = $this->providerManager->getProvider($version->getExtensionProvider());
$t3xFileName = $provider->getFileUrl($version, 't3x');
$zipFileName = $extensionMediaPath . basename($provider->getFileName($version, 'zip'));
// Check if zip file already exists
if (Tx_TerFe2_Utility_File::fileExists($zipFileName)) {
return $zipFileName;
}
// Check file hash
$fileHash = Tx_TerFe2_Utility_File::getFileHash($t3xFileName);
if ($fileHash != $version->getFileHash()) {
return '';
}
// Create zip file
$result = Tx_TerFe2_Utility_Archive::convertT3xToZip($t3xFileName, $zipFileName);
if (!empty($result)) {
return $zipFileName;
}
return '';
}
/**
* Create images for given version
*
* @param Tx_TerFe2_Domain_Model_Version $version Path to t3x file
* @param string $extensionMediaPath Path to media files
* @return boolean TRUE if success
*/
protected function createImages(Tx_TerFe2_Domain_Model_Version $version, $extensionMediaPath)
{
if (empty($extensionMediaPath)) {
return FALSE;
}
// Get image files
$imageFiles = array();
$mediaObjects = $version->getMedia();
foreach ($mediaObjects as $media) {
if ($media->getType() === 'image') {
// Source must contains only image file name without path
$imageFiles[] = $extensionMediaPath . $media->getSource();
}
}
if (empty($imageFiles)) {
return TRUE;
}
foreach ($this->imageSizes as $imageSize) {
if (empty($this->setup['settings.'][$imageSize . 'Image'])) {
continue;
}
$images = Tx_TerFe2_Service_Image::processImages($imageFiles, $this->setup['settings.'][$imageSize . 'Image']);
if (empty($images)) {
throw new Exception('Could not create image files');
}
}
return TRUE;
}
}
<?php
/*******************************************************************
* 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!
******************************************************************/
/**
* Additional field provider for the create extension files task
*/
class Tx_TerFe2_Task_CreateExtensionFilesTaskAdditionalFieldProvider extends Tx_TerFe2_Task_AbstractAdditionalFieldProvider
{
/**
* Add some input fields to configure the task
*
* @return void
*/
protected function addAdditionalFields()
{
}
/**
* Checks the given values
*
* @param array $submittedData Submitted user data
* @return boolean TRUE if validation was ok
*/
protected function checkAdditionalFields(array $submittedData)
{
return TRUE;
}
}
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2012 Thomas Löffler <thomas.loeffler@typo3.org>
*
* 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!
******************************************************************/
class Tx_TerFe2_Task_DownloadCounterTask extends tx_scheduler_Task
{
/**
* sums up all version downloads and
* writes it to the extension
*
* @return bool
*/
public function execute()
{
$extensions = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'uid, last_version, ext_key',
'tx_terfe2_domain_model_extension',
'deleted = 0 AND hidden = 0 AND versions > 0'
);
if (!empty($extensions)) {
foreach ($extensions as $ext) {
$updateExtension = array();
// get the downloads of all versions
$downloads = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'SUM(download_counter) AS downloads, SUM(frontend_download_counter) AS fe_downloads',
'tx_terfe2_domain_model_version',
'deleted = 0 AND hidden = 0 AND extension = ' . $ext['uid'],
'extension'
);
$updateExtension['downloads'] = $downloads['downloads'] + $downloads['fe_downloads'];
// check if latest version is right (upload_date, not version)
$versions = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'uid,extension_provider,t3x_file_size,version_string',
'tx_terfe2_domain_model_version',
'deleted = 0 AND hidden = 0 AND extension = ' . $ext['uid'],
FALSE,
'upload_date DESC'
);
foreach ($versions as $version) {
$updateVersion = array();
if ($version['extension_provider'] == '') {
$updateVersion['extension_provider'] = 'file';
}
$folder1 = substr($ext['ext_key'], 0, 1);
$folder2 = substr($ext['ext_key'], 1, 1);
$fileName = PATH_site . 'fileadmin/ter/' . $folder1 . '/' . $folder2 . '/' . $ext['ext_key'] . '_' . $version['version_string'] . '.t3x';
if ($version['t3x_file_size'] == 0 && file_exists($fileName)) {
$updateVersion['t3x_file_size'] = filesize($fileName);
}
if (!empty($updateVersion)) {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'uid = ' . $version['uid'], $updateVersion);
}
}
$latestVersion = $versions[0];
// fix for first upload
$extensions = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'crdate',
'tx_ter_extensions',
'extensionkey = "' . $ext['ext_key'] . '"',
FALSE,
'crdate ASC'
);
$firstUpload = $extensions[0];
if ($latestVersion['uid'] != $ext['last_version']) {
$updateExtension['tstamp'] = time();
$updateExtension['last_version'] = $latestVersion['uid'];
}
if ($firstUpload['crdate'] > 0) {
$updateExtension['crdate'] = $firstUpload['crdate'];
}
if (!empty($updateExtension)) {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_extension', 'uid = ' . $ext['uid'], $updateExtension);
/** @var Tx_TerFe2_Service_Notification $notificationService */
$notificationService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_TerFe2_Service_Notification');
// update the EXT:solr Index Queue
$notificationService->notifySolrIndexQueue($ext['uid']);
}
}
}
// set state as string
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = "0"', array('state' => 'alpha'));
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = "1"', array('state' => 'beta'));
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = "2"', array('state' => 'stable'));
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = "3"', array('state' => 'experimental'));
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = "4"', array('state' => 'test'));
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = "5"', array('state' => 'obsolete'));
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = "6"', array('state' => 'excludeFromUpdates'));
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = "999"', array('state' => 'n/a'));
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'state = ""', array('state' => 'n/a'));
return TRUE;
}
}
<?php
/*******************************************************************
* 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!
******************************************************************/
/**
* Update version details
*/
class Tx_TerFe2_Task_UpdateDetailsTask extends Tx_TerFe2_Task_AbstractTask
{
/**
* @var boolean
*/
public $recalculateDownloads = TRUE;
/**
* @var Tx_TerFe2_Domain_Repository_VersionRepository
*/
protected $versionRepository;
/**
* @var Tx_TerFe2_Provider_ProviderManager
*/
protected $providerManager;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
*/
protected $persistenceManager;
/**
* Initialize task
*
* @return void
*/
public function initializeTask()
{
$this->providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$this->objectBuilder = $this->objectManager->get('Tx_TerFe2_Object_ObjectBuilder');
$this->persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
$this->versionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_VersionRepository');
}
/**
* Execute the task
*
* @param integer $lastRun Timestamp of the last run
* @param integer $offset Starting point
* @param integer $count Element count to process at once
* @return boolean TRUE on success
*/
protected function executeTask($lastRun, $offset, $count)
{
$versions = $this->versionRepository->findAll($offset, $count);
if ($versions->count() === 0) {
return FALSE;
}
foreach ($versions as $version) {
if ($version instanceof Tx_TerFe2_Domain_Model_Version) {
$provider = $version->getExtensionProvider();
$persist = FALSE;
$attributes = array();
if (!empty($provider)) {
$attributes = $this->providerManager->getProvider($provider)->getVersionDetails($version);
}
if (!empty($attributes)) {
$version = $this->objectBuilder->update($version, $attributes);
$persist = TRUE;
}
if (!empty($this->recalculateDownloads) and $version->getExtension() instanceof Tx_TerFe2_Domain_Model_Extension) {
$version->getExtension()->recalculateDownloads();
$persist = TRUE;
}
if ($persist) {
$this->persistenceManager->persistAll();
}
}
}
return TRUE;
}
}
<?php
/*******************************************************************
* 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!
******************************************************************/
/**
* Additional field provider for the update downloads task
*/
class Tx_TerFe2_Task_UpdateDetailsTaskAdditionalFieldProvider extends Tx_TerFe2_Task_AbstractAdditionalFieldProvider
{
/**
* Add some input fields to configure the task
*
* @return void
*/
protected function addAdditionalFields()
{
$this->addCheckboxField('recalculateDownloads', FALSE);
}
/**
* Checks the given values
*
* @param array $submittedData Submitted user data
* @return boolean TRUE if validation was ok
*/
protected function checkAdditionalFields(array $submittedData)
{
return TRUE;
}
}
<?php
/*******************************************************************
* 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!
******************************************************************/
/**
* Update extension list task
*/
class Tx_TerFe2_Task_UpdateExtensionListTask extends Tx_TerFe2_Task_AbstractTask