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

[TASK] Changes ImportExtensionsFromQueueTask

parent c6bda616
Pipeline #508 passed with stages
in 2 minutes and 45 seconds
<?php
namespace T3o\TerFe2\Task;
/**
......@@ -17,6 +18,9 @@ namespace T3o\TerFe2\Task;
use TYPO3\CMS\Extbase\Scheduler\Task;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
/**
* Class ImportExtensionsFromQueueTask
......@@ -43,7 +47,8 @@ class ImportExtensionsFromQueueTask extends Task
// finish task if no extensions in queue
if (empty($extensionsFromQueue)) {
GeneralUtility::sysLog('No new extensions in queue table', 'ter_fe2', 1);
return TRUE;
return true;
}
foreach ($extensionsFromQueue as $ext) {
......@@ -51,11 +56,15 @@ class ImportExtensionsFromQueueTask extends Task
if (!$this->versionExists($extensionData)) {
$extUid = $this->extensionExists($extensionData);
$this->saveExtension($extUid, $extensionData, $ext['crdate']);
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 (ExtensionManagementUtility::isLoaded('solr')) {
$indexQueue = GeneralUtility::makeInstance(\ApacheSolrForTypo3\Solr\IndexQueue\Queue::class);
$indexQueue = GeneralUtility::makeInstance(Queue::class);
$indexQueue->updateItem('tx_terfe2_domain_model_extension', $extUid);
}
}
......@@ -67,7 +76,7 @@ class ImportExtensionsFromQueueTask extends Task
$this->removeExtensionFromQueue($ext['extensionuid']);
}
return TRUE;
return true;
}
/**
......@@ -76,11 +85,11 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function removeExtensionFromQueue($extUid)
{
$updateQueue = array(
$updateQueue = [
'tstamp' => time(),
'imported_to_fe' => 1
);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_ter_extensionqueue', 'extensionuid = ' . $extUid, $updateQueue);
];
$this->getDatabaseConnection()->exec_UPDATEquery('tx_ter_extensionqueue', 'extensionuid = ' . $extUid, $updateQueue);
}
/**
......@@ -91,11 +100,11 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function getExtensionsFromQueue()
{
$extensions = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
$extensions = $this->getDatabaseConnection()->exec_SELECTgetRows(
'extensionuid,crdate',
'tx_ter_extensionqueue',
'NOT deleted AND NOT imported_to_fe',
FALSE,
false,
'crdate'
);
......@@ -111,11 +120,12 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function getExtensionData($extensionUid)
{
$extData = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
$extData = $this->getDatabaseConnection()->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.uid = ' . (int)$extensionUid
);
return $extData;
}
......@@ -129,14 +139,15 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function versionExists($extData)
{
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
$res = $this->getDatabaseConnection()->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 = "' . $this->getD($extData['version']) . '"
AND tx_terfe2_domain_model_extension.ext_key = "' . mysql_real_escape_string($extData['extensionkey']) . '"'
AND tx_terfe2_domain_model_version.version_string = "' . $this->getDatabaseConnection()->quoteStr($extData['version'], 'tx_terfe2_domain_model_version') . '"
AND tx_terfe2_domain_model_extension.ext_key = "' . $this->getDatabaseConnection()->quoteStr($extData['extensionkey'], 'tx_terfe2_domain_model_extension') . '"'
);
return (boolean)$GLOBALS['TYPO3_DB']->sql_num_rows($res);
return (boolean)$this->getDatabaseConnection()->sql_num_rows($res);
}
/**
......@@ -146,14 +157,15 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function extensionExists($extData)
{
$extRec = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
$extRec = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'tx_terfe2_domain_model_extension',
'NOT deleted AND ext_key = "' . mysql_real_escape_string($extData['extensionkey']) . '"'
'NOT deleted AND ext_key = "' . $this->getDatabaseConnection()->quoteStr($extData['extensionkey'], 'tx_terfe2_domain_model_extension') . '"'
);
if ($extRec) {
return $extRec['uid'];
}
return $this->createExtension($extData);
}
......@@ -164,7 +176,7 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function createExtension($extData)
{
$insertExtension = array(
$insertExtension = [
'pid' => $this->pid,
'ext_key' => $extData['extensionkey'],
'last_upload' => time(),
......@@ -174,10 +186,11 @@ class ImportExtensionsFromQueueTask extends Task
'frontend_user' => $extData['lastuploadbyusername'],
'crdate' => time(),
'tstamp' => time()
);
];
$this->getDatabaseConnection()->exec_INSERTquery('tx_terfe2_domain_model_extension', $insertExtension);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_terfe2_domain_model_extension', $insertExtension);
return $GLOBALS['TYPO3_DB']->sql_insert_id();
return $this->getDatabaseConnection()->sql_insert_id();
}
/**
......@@ -203,7 +216,7 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function createVersion($extUid, $extData, $crdate)
{
$extensionModel = GeneralUtility::makeInstance(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
$extensionModel = GeneralUtility::makeInstance(Extension::class);
$states = $extensionModel->getDefaultState(null);
$categories = \Tx_TerFe2_Utility_Category::getDefaultCategories();
......@@ -211,7 +224,7 @@ class ImportExtensionsFromQueueTask extends Task
$folder2 = substr($extData['extensionkey'], 1, 1);
$t3xFile = PATH_site . 'fileadmin/ter/' . $folder1 . '/' . $folder2 . '/' . $extData['extensionkey'] . '_' . $extData['version'] . '.t3x';
$insertVersion = array(
$insertVersion = [
'pid' => $this->pid,
'crdate' => $crdate,
'tstamp' => time(),
......@@ -219,7 +232,7 @@ class ImportExtensionsFromQueueTask extends Task
'title' => $extData['title'],
'description' => $extData['description'],
'author' => $this->createAuthor($extData),
'version_number' => \TYPO3\CMS\Core\Utility\GeneralUtility::int_from_ver($extData['version']),
'version_number' => VersionNumberUtility::convertVersionNumberToInteger($extData['version']),
'version_string' => $extData['version'],
'upload_date' => $crdate,
'upload_comment' => $extData['uploadcomment'],
......@@ -247,10 +260,11 @@ class ImportExtensionsFromQueueTask extends Task
'has_images' => 0,
't3x_file_size' => @filesize($t3xFile),
'zip_file_size' => 0
);
];
$this->getDatabaseConnection()->exec_INSERTquery('tx_terfe2_domain_model_version', $insertVersion);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_terfe2_domain_model_version', $insertVersion);
return $GLOBALS['TYPO3_DB']->sql_insert_id();
return $this->getDatabaseConnection()->sql_insert_id();
}
/**
......@@ -260,12 +274,16 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function updateExtension($versionUid, $extUid)
{
$updateExtension = array(
$updateExtension = [
'tstamp' => time(),
'versions' => $this->getNumberOfVersions($extUid),
'last_version' => $versionUid
];
$this->getDatabaseConnection()->exec_UPDATEquery(
'tx_terfe2_domain_model_extension',
'uid = ' . $extUid,
$updateExtension
);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_extension', 'uid = ' . $extUid, $updateExtension);
}
/**
......@@ -275,12 +293,13 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function getNumberOfVersions($extUid)
{
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
$res = $this->getDatabaseConnection()->exec_SELECTquery(
'uid',
'tx_terfe2_domain_model_version',
'extension = ' . $extUid . ' AND NOT deleted'
);
return $GLOBALS['TYPO3_DB']->sql_num_rows($res);
return $this->getDatabaseConnection()->sql_num_rows($res);
}
/**
......@@ -296,23 +315,24 @@ class ImportExtensionsFromQueueTask extends Task
$relationKey = $relation['extensionKey'];
$version = $this->getVersionByRange($relation['versionRange']);
if ($relationKey) {
$insertRelation = array(
$insertRelation = [
'relation_type' => $relationType,
'relation_key' => $relationKey,
'minimum_version' => $version[0],
'maximum_version' => $version[1],
'version' => $versionUid,
'related_extension' => $this->getUidOfRelatedExtension($relationKey)
);
];
$countRelations++;
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_terfe2_domain_model_relation', $insertRelation);
$this->getDatabaseConnection()->exec_INSERTquery('tx_terfe2_domain_model_relation', $insertRelation);
}
}
$updateVersion = array(
$updateVersion = [
'software_relations' => $countRelations
);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_terfe2_domain_model_version', 'uid = ' . $versionUid, $updateVersion);
];
$this->getDatabaseConnection()
->exec_UPDATEquery('tx_terfe2_domain_model_version', 'uid = ' . $versionUid, $updateVersion);
}
/**
......@@ -322,14 +342,15 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function getUidOfRelatedExtension($extKey)
{
$extRec = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
$extRec = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'tx_terfe2_domain_model_extension',
'ext_key = "' . mysql_real_escape_string($extKey) . '" AND NOT deleted'
'ext_key = "' . $this->getDatabaseConnection()->quoteStr($extKey, 'tx_terfe2_domain_model_extension') . '" AND NOT deleted'
);
if ($extRec['uid']) {
return $extRec['uid'];
}
return 0;
}
......@@ -350,14 +371,13 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function authorExists($extData)
{
$authorRec = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
$authorRec = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'tx_terfe2_domain_model_author',
'NOT deleted
AND username = "' . mysql_real_escape_string($extData['lastuploadbyusername']) . '"
AND name = "' . mysql_real_escape_string($extData['authorname']) . '"
AND email = "' . mysql_real_escape_string($extData['authoremail']) . '"
AND company = "' . mysql_real_escape_string($extData['authorcompany']) . '"'
'NOT deleted AND username = "' . $this->getDatabaseConnection()->quoteStr($extData['lastuploadbyusername'], 'tx_terfe2_domain_model_author') . '"
AND name = "' . $this->getDatabaseConnection()->quoteStr($extData['authorname'], 'tx_terfe2_domain_model_author') . '"
AND email = "' . $this->getDatabaseConnection()->quoteStr($extData['authoremail'], 'tx_terfe2_domain_model_author') . '"
AND company = "' . $this->getDatabaseConnection()->quoteStr($extData['authorcompany'], 'tx_terfe2_domain_model_author') . '"'
);
if ($authorRec['uid']) {
return $authorRec['uid'];
......@@ -373,16 +393,17 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function createAuthor($extData)
{
$insertAuthor = array(
$insertAuthor = [
'name' => $extData['authorname'],
'email' => $extData['authoremail'],
'company' => $extData['authorcompany'],
'username' => $extData['lastuploadbyusername'],
'frontend_user' => $this->getFeUserUidFromUsername($extData['lastuploadbyusername'])
);
];
$this->getDatabaseConnection()->exec_INSERTquery('tx_terfe2_domain_model_author', $insertAuthor);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_terfe2_domain_model_author', $insertAuthor);
return $GLOBALS['TYPO3_DB']->sql_insert_id();
return $this->getDatabaseConnection()->sql_insert_id();
}
/**
......@@ -392,15 +413,16 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function getFeUserUidFromUsername($username)
{
$userRec = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
$userRec = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'fe_users',
'username = "' . mysql_real_escape_string($username) . '"'
'username = "' . $this->getDatabaseConnection()->quoteStr($username, 'fe_users') . '"'
);
if ($userRec['uid']) {
return $userRec['uid'];
}
return FALSE;
return false;
}
/**
......@@ -411,11 +433,18 @@ class ImportExtensionsFromQueueTask extends Task
*/
protected function getVersionByRange($version)
{
$version = \TYPO3\CMS\Extbase\Utility\ArrayUtility::trimExplode('-', $version);
$minimum = (!empty($version[0]) ? \TYPO3\CMS\Core\Utility\GeneralUtility::int_from_ver($version[0]) : 0);
$maximum = (!empty($version[1]) ? \TYPO3\CMS\Core\Utility\GeneralUtility::int_from_ver($version[1]) : 0);
$version = GeneralUtility::trimExplode('-', $version);
$minimum = (!empty($version[0]) ? VersionNumberUtility::convertVersionNumberToInteger($version[0]) : 0);
$maximum = (!empty($version[1]) ? VersionNumberUtility::convertVersionNumberToInteger($version[1]) : 0);
return array($minimum, $maximum);
return [$minimum, $maximum];
}
/**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
private function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
}
......@@ -90,7 +90,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_
);
// Register import from queue task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_ImportExtensionsFromQueueTask'] = array(
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\TerFe2\Task\ImportExtensionsFromQueueTask::class] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_importextensionsfromqueuetask.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_importextensionsfromqueuetask.description',
......@@ -104,14 +104,14 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_
);
// Register check for outdated extensions tassk
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_CheckForOutdatedExtensions'] = array(
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\TerFe2\Task\CheckForOutdatedExtensions::class] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_checkforoutdatedextensions.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_checkforoutdatedextensions.description',
);
// Register check for expired extensions tassk
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_CheckForExpiredExtensions'] = array(
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\TerFe2\Task\CheckForExpiredExtensions::class] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_checkforexpiredextensions.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_checkforexpiredextensions.description',
......
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