Commit c6bda616 authored by Thomas Löffler's avatar Thomas Löffler
Browse files

[TASK] First bunch of changes

parent 849abbeb
Pipeline #506 passed with stages
in 2 minutes and 55 seconds
<?php
namespace T3o\TerFe2\Task;
/**
* This file is part of the TYPO3 CMS project.
*
......@@ -12,16 +14,22 @@
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Extbase\Scheduler\Task;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Class Tx_TerFe2_Task_CheckForExpiredExtensions
* Class CheckForExpiredExtensions
*/
class Tx_TerFe2_Task_CheckForExpiredExtensions extends tx_scheduler_Task
class CheckForExpiredExtensions extends Task
{
/**
* @var array
*/
protected $blacklistUsers = array();
protected $blacklistUsers = [];
/**
* Execute Task
......@@ -30,11 +38,11 @@ class Tx_TerFe2_Task_CheckForExpiredExtensions extends tx_scheduler_Task
*/
public function execute()
{
$this->blacklistUsers = array(
$this->blacklistUsers = [
'abandoned_extensions',
'typo3v4',
'docteam'
);
];
$expiringExtensions = $this->getDatabaseConnection()->exec_SELECTgetRows(
'uid, ext_key, frontend_user',
'tx_terfe2_domain_model_extension',
......@@ -44,7 +52,7 @@ class Tx_TerFe2_Task_CheckForExpiredExtensions extends tx_scheduler_Task
);
// group extensions by owner
$expiredExtensionsByOwner = array();
$expiredExtensionsByOwner = [];
foreach ($expiringExtensions as $expiringExtension) {
if ($expiringExtension['ext_key'] && $expiringExtension['frontend_user']) {
$expiredExtensionsByOwner[$expiringExtension['frontend_user']][] = $expiringExtension;
......@@ -52,26 +60,30 @@ class Tx_TerFe2_Task_CheckForExpiredExtensions extends tx_scheduler_Task
}
foreach ($expiredExtensionsByOwner as $username => $extensions) {
if (in_array($username, $this->blacklistUsers, TRUE)) {
if (in_array($username, $this->blacklistUsers, true)) {
continue;
}
$frontendUser = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid, username, email',
'fe_users',
'username = ' . $this->getDatabaseConnection()->fullQuoteStr($username, 'fe_users')
. \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('fe_users')
. \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('fe_users')
. BackendUtility::BEenableFields('fe_users')
. BackendUtility::deleteClause('fe_users')
);
if (!empty($frontendUser) && \TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($frontendUser['email'])) {
if (!empty($frontendUser) && GeneralUtility::validEmail($frontendUser['email'])) {
$to = $frontendUser['email'];
$subject = 'Your extension keys are going to expire!';
/** @var Tx_Fluid_View_StandaloneView $body */
$body = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Fluid_View_StandaloneView');
$body->setTemplatePathAndFilename(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:ter_fe2/Resources/Private/Templates/Mail/ExpiredExtensions.html'));
/** @var StandaloneView $body */
$body = GeneralUtility::makeInstance(StandaloneView::class);
$body->setTemplatePathAndFilename(
GeneralUtility::getFileAbsFileName(
'EXT:ter_fe2/Resources/Private/Templates/Mail/ExpiredExtensions.html'
)
);
$body->assign('extensions', $extensions);
$body->assign('user', $frontendUser);
/** @var \TYPO3\CMS\Core\Mail\MailMessage $mail */
$mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
/** @var MailMessage $mail */
$mail = GeneralUtility::makeInstance(MailMessage::class);
$mail->addFrom('maintenance@typo3.org');
$mail->setTo($to);
$mail->setSubject($subject);
......@@ -142,4 +154,4 @@ class Tx_TerFe2_Task_CheckForExpiredExtensions extends tx_scheduler_Task
{
return $GLOBALS['TYPO3_DB'];
}
}
\ No newline at end of file
}
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2014 Tomas Norre <tomas.norre@gmail.com>
* (c) 2014 Thorsten Schneider <mail@thorsten-schneider.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.
namespace T3o\TerFe2\Task;
/**
* This file is part of the TYPO3 CMS project.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* 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.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Extbase\Scheduler\Task;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Persistence\Generic\Session;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
/**
* Class Tx_TerFe2_Task_CheckForOutdatedExtensions
* Class CheckForOutdatedExtensions
*/
class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
class CheckForOutdatedExtensions extends Task
{
/**
......@@ -36,7 +35,7 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
protected $persistenceManager;
/**
* @var Tx_TerFe2_Domain_Repository_VersionRepository
* @var \Tx_TerFe2_Domain_Repository_VersionRepository
*/
protected $versionRepository;
......@@ -58,7 +57,7 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
/**
* @var array
*/
protected $supportedCoreVersions = array();
protected $supportedCoreVersions = [];
/**
* @var int
......@@ -66,7 +65,7 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
protected $releaseDateOfOldestSupportedTypo3Version;
/**
* @var tx_solr_indexqueue_Queue
* @var \ApacheSolrForTypo3\Solr\IndexQueue\Queue
*/
protected $solrIndexQueue;
......@@ -77,12 +76,13 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
*/
public function initializeTask()
{
$this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
$this->persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
$this->session = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Session::class);
$this->versionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_VersionRepository');
$this->coreVersions = json_decode(\TYPO3\CMS\Core\Utility\GeneralUtility::getURL(PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json'), TRUE);
$this->solrIndexQueue = $this->objectManager->get('tx_solr_indexqueue_Queue');
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
$this->session = $this->objectManager->get(Session::class);
$this->versionRepository = $this->objectManager->get(\Tx_TerFe2_Domain_Repository_VersionRepository::class);
$this->coreVersions = json_decode(GeneralUtility::getURL(PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json'),
true);
$this->solrIndexQueue = $this->objectManager->get(Queue::class);
}
/**
......@@ -107,7 +107,7 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
$this->checkVersion($version);
}
return TRUE;
return true;
}
/**
......@@ -117,7 +117,7 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
*/
public function getNotOutdatedAndSecureVersions()
{
$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
$rows = $this->getDatabaseConnection()->exec_SELECTgetRows(
'uid',
'tx_terfe2_domain_model_version',
'NOT deleted AND NOT hidden AND review_state >= 0',
......@@ -148,23 +148,23 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
/**
* Get the latest and oldest supported TYPO3 Versions.
*
* @throws RuntimeException
* @throws \RuntimeException
* @return void
*/
public function getLatestAndOldestSupportedTypo3Versions()
{
if ($this->coreVersions === NULL) {
throw new RuntimeException('typo3.org JSON not accessible!', 1399140291);
if ($this->coreVersions === null) {
throw new \RuntimeException('typo3.org JSON not accessible!', 1399140291);
}
// Collect currently supported core versions
$oldestSupportedCoreVersion = '99.99.99';
$latestSupportedCoreVersion = '0.0.0';
$allSupportedCoreVersions = array();
$allSupportedCoreVersions = [];
foreach ($this->coreVersions as $version => $coreInfo) {
// Only use keys that represent a branch number
if (preg_match('/^\d+\.\d+$/', $version) || preg_match('/^\d+$/', $version)) {
if ($coreInfo['active'] == TRUE) {
if ($coreInfo['active'] == true) {
$allSupportedCoreVersions[] = $version;
......@@ -193,41 +193,42 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
}
}
$this->supportedCoreVersions = array(
$this->supportedCoreVersions = [
'latest' => $latestSupportedCoreVersion,
'oldest' => $oldestSupportedCoreVersion,
'all' => $allSupportedCoreVersions,
);
];
}
/**
* @param Tx_TerFe2_Domain_Model_Relation $dependency
* @param \Tx_TerFe2_Domain_Model_Relation $dependency
*
* @return boolean
*/
public function isVersionDependingOnAnActiveSupportedTypo3Version($dependency)
{
$result = FALSE;
$result = false;
if ($dependency instanceof Tx_TerFe2_Domain_Model_Relation) {
if ($dependency instanceof \Tx_TerFe2_Domain_Model_Relation) {
$extensionMinimumVersion = $dependency->getMinimumVersion();
$extensionMaximumVersion = $dependency->getMaximumVersion();
foreach ($this->supportedCoreVersions['all'] as $version) {
$version = (string)$version;
// gets core version x.x.0
$supportedMinimumVersion = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger($version . '.0');
$extensionMinimumVersionAsString = Tx_TerFe2_Utility_Version::versionFromInteger($extensionMinimumVersion);
$supportedMinimumVersion = VersionNumberUtility::convertVersionNumberToInteger($version . '.0');
$extensionMinimumVersionAsString = VersionNumberUtility::convertIntegerToVersionNumber($extensionMinimumVersion);
/*
* checks if extension dependency lies within the first release of the main release version
* or extension minimum version begins with main release version
*/
if (($supportedMinimumVersion >= $extensionMinimumVersion || strpos($extensionMinimumVersionAsString, $version) === 0)
if (
($supportedMinimumVersion >= $extensionMinimumVersion || strpos($extensionMinimumVersionAsString, $version) === 0)
&& $supportedMinimumVersion <= $extensionMaximumVersion
) {
$result = TRUE;
$result = true;
break;
}
}
......@@ -243,43 +244,43 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
*/
protected function checkVersion($version)
{
/** @var Tx_TerFe2_Domain_Model_Version $version */
/** @var \Tx_TerFe2_Domain_Model_Version $version */
$version = $this->versionRepository->findByUid($version['uid']);
if (!$version instanceof Tx_TerFe2_Domain_Model_Version) {
if (!$version instanceof \Tx_TerFe2_Domain_Model_Version) {
return;
}
$isOutdated = FALSE;
$isOutdated = false;
if ($version->getUploadDate() === NULL) {
$isOutdated = TRUE;
if ($version->getUploadDate() === null) {
$isOutdated = true;
// Check if date is set
} elseif ($version->getUploadDate() < $this->releaseDateOfOldestSupportedTypo3Version) {
$isOutdated = TRUE;
$isOutdated = true;
// Check upload date against oldestActiveTYPO3Version first release date.
} elseif (!$this->isVersionDependingOnAnActiveSupportedTypo3Version($version->getTypo3Dependency())) {
$isOutdated = TRUE;
$isOutdated = true;
// Check against dependency against TYPO3 not actively supported
}
if ($isOutdated) {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery(
$this->getDatabaseConnection()->exec_UPDATEquery(
'tx_terfe2_domain_model_version',
'uid = ' . $version->getUid(),
array(
[
'review_state' => -2
)
]
);
if ($version->getExtension() && $version->getExtension()->getUid()) {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery(
$this->getDatabaseConnection()->exec_UPDATEquery(
'tx_terfe2_domain_model_extension',
'uid = ' . $version->getExtension()->getUid(),
array(
[
'tstamp' => time()
)
]
);
$this->solrIndexQueue->updateItem('tx_terfe2_domain_model_extension', $version->getExtension()->getUid());
}
......@@ -293,14 +294,22 @@ class Tx_TerFe2_Task_CheckForOutdatedExtensions extends tx_scheduler_Task
*
* prevent memory leaks on the long running scheduler task
*
* @param Tx_TerFe2_Domain_Model_Version $version
* @param \Tx_TerFe2_Domain_Model_Version $version
*/
public function cleanupMemory($version)
{
$this->session->unregisterReconstitutedObject($version);
$this->session->unregisterReconstitutedEntity($version);
foreach ($version->getSoftwareRelations() as $relation) {
/** @var $relation Tx_TerFe2_Domain_Model_Relation */
$this->session->unregisterReconstitutedObject($relation);
/** @var $relation \Tx_TerFe2_Domain_Model_Relation */
$this->session->unregisterReconstitutedEntity($relation);
}
}
}
\ No newline at end of file
/**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
private function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
}
<?php
namespace T3o\TerFe2\Task;
/*******************************************************************
* Copyright notice
/**
* This file is part of the TYPO3 CMS project.
*
* (c) 2013 Thomas Löffler <thomas.loeffler@typo3.org>
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* All rights reserved
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* 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_ImportExtensionsFromQueueTask extends tx_scheduler_Task
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Extbase\Scheduler\Task;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* Class ImportExtensionsFromQueueTask
*/
class ImportExtensionsFromQueueTask extends Task
{
/**
......@@ -44,7 +42,7 @@ class Tx_TerFe2_Task_ImportExtensionsFromQueueTask extends tx_scheduler_Task
// finish task if no extensions in queue
if (empty($extensionsFromQueue)) {
\TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('No new extensions in queue table', 'ter_fe2', 1);
GeneralUtility::sysLog('No new extensions in queue table', 'ter_fe2', 1);
return TRUE;
}
......@@ -53,21 +51,29 @@ class Tx_TerFe2_Task_ImportExtensionsFromQueueTask extends tx_scheduler_Task
if (!$this->versionExists($extensionData)) {
$extUid = $this->extensionExists($extensionData);
$this->saveExtension($extUid, $extensionData, $ext['crdate']);
\TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Extension "' . $extensionData['extensionkey'] . '", version ' . $extensionData['version'] . ' saved in ter_fe2', 'ter_fe2', 1);
GeneralUtility::sysLog('Extension "' . $extensionData['extensionkey'] . '", version ' . $extensionData['version'] . ' saved in ter_fe2', 'ter_fe2', 1);
// update the EXT:solr Index Queue
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('solr')) {
$indexQueue = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_solr_indexqueue_Queue');
if (ExtensionManagementUtility::isLoaded('solr')) {
$indexQueue = GeneralUtility::makeInstance(\ApacheSolrForTypo3\Solr\IndexQueue\Queue::class);
$indexQueue->updateItem('tx_terfe2_domain_model_extension', $extUid);
}
}
\TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Extension "' . $extensionData['extensionkey'] . '" still exists with version ' . $extensionData['version'] . ' in ter_fe2', 'ter_fe2', 1);
GeneralUtility::sysLog(
'Extension "' . $extensionData['extensionkey'] . '" still exists with version ' . $extensionData['version'] . ' in ter_fe2',
'ter_fe2',
1
);
$this->removeExtensionFromQueue($ext['extensionuid']);
}
return TRUE;
}
/**
* @param int $extUid
* @return void
*/
public function removeExtensionFromQueue($extUid)
{
$updateQueue = array(
......@@ -107,8 +113,7 @@ class Tx_TerFe2_Task_ImportExtensionsFromQueueTask extends tx_scheduler_Task
{
$extData = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'tx_ter_extensions.*, tx_ter_extensiondetails.*',
'tx_ter_extensions
LEFT JOIN tx_ter_extensiondetails ON tx_ter_extensions.uid = tx_ter_extensiondetails.extensionuid',
'tx_ter_extensions LEFT JOIN tx_ter_extensiondetails ON tx_ter_extensions.uid = tx_ter_extensiondetails.extensionuid',
'tx_ter_extensions.uid = ' . (int)$extensionUid
);
return $extData;
......@@ -126,11 +131,10 @@ class Tx_TerFe2_Task_ImportExtensionsFromQueueTask extends tx_scheduler_Task
{
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_terfe2_domain_model_version.uid',
'tx_terfe2_domain_model_version
LEFT JOIN tx_terfe2_domain_model_extension ON tx_terfe2_domain_model_extension.uid = tx_terfe2_domain_model_version.extension',
'NOT tx_terfe2_domain_model_version.deleted
AND tx_terfe2_domain_model_version.version_string = "' . mysql_real_escape_string($extData['version']) . '"
AND tx_terfe2_domain_model_extension.ext_key = "' . mysql_real_escape_string($extData['extensionkey']) . '"'
'tx_terfe2_domain_model_version LEFT JOIN tx_terfe2_domain_model_extension ON tx_terfe2_domain_model_extension.uid = tx_terfe2_domain_model_version.extension',
'NOT tx_terfe2_domain_model_version.deleted
AND tx_terfe2_domain_model_version.version_string = "' . $this->getD($extData['version']) . '"
AND tx_terfe2_domain_model_extension.ext_key = "' . mysql_real_escape_string($extData['extensionkey']) . '"'
);
return (boolean)$GLOBALS['TYPO3_DB']->sql_num_rows($res);
}
......@@ -199,8 +203,9 @@ class Tx_TerFe2_Task_ImportExtensionsFromQueueTask extends tx_scheduler_Task
*/
public function createVersion($extUid, $extData, $crdate)
{
$states = tx_em_Tools::getDefaultState(NULL);
$categories = Tx_TerFe2_Utility_Category::getDefaultCategories();
$extensionModel = GeneralUtility::makeInstance(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
$states = $extensionModel->getDefaultState(null);
$categories = \Tx_TerFe2_Utility_Category::getDefaultCategories();
$folder1 = substr($extData['extensionkey'], 0, 1);
$folder2 = substr($extData['extensionkey'], 1, 1);
......@@ -251,6 +256,7 @@ class Tx_TerFe2_Task_ImportExtensionsFromQueueTask extends tx_scheduler_Task
/**
* @param int $versionUid
* @param int $extUid
* @return void
*/
public function updateExtension($versionUid, $extUid)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment