Commit 854bac7c authored by Andreas Wolf's avatar Andreas Wolf

Merge branch 'add-task-to-get-old-keys-from-ter' into 'develop'

Add task to import all keys without version into terfe2

Closes #213

See merge request !264
parents 7290949c d1205646
Pipeline #2718 passed with stages
in 4 minutes and 38 seconds
<?php
namespace T3o\TerFe2\Task;
use T3o\TerFe2\Utility\Category;
/*
* This file is part of the TYPO3 CMS project.
*
* 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.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This is a one-time task to get all extension keys from ter tables
* to the new ter_fe2 tables.
* Then the process for expired extensions can run.
*
* @author Thomas Löffler <loeffler@spooner-web.de>
*/
class ImportAllExtensionKeysTask extends \TYPO3\CMS\Extbase\Scheduler\Task
{
/**
* PID for all extension related records
*
* @var int $pid
*/
protected $pid = 2;
/**
* executes the importer
*
* @return bool
*/
public function execute()
{
$extensionKeysFromTer = $this->getAllExtensionKeysFromTer();
foreach ($extensionKeysFromTer as $extensionData) {
if (!$this->extensionExists($extensionData)) {
$versionCount = $this->getVersionCount($extensionData['extensionkey']);
if ($versionCount === 0) {
$this->createExtension($extensionData);
}
}
}
return true;
}
/**
* Gets the extension key data out of ter tables
*
* @return array $extData
*/
public function getAllExtensionKeysFromTer(): array
{
$extData = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'*',
'tx_ter_extensionkeys',
'',
false,
'crdate'
);
return $extData;
}
/**
* @param array $extData
*
* @return int $uid extension uid
*/
public function extensionExists($extData)
{
$extRec = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'uid',
'tx_terfe2_domain_model_extension',
'NOT deleted AND ext_key = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($extData['extensionkey'], 'tx_terfe2_domain_model_extension')
);
return !empty($extRec);
}
/**
* @param $extensionKey
* @return int
*/
public function getVersionCount($extensionKey)
{
$versionCounter = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
'uid',
'tx_ter_extensions',
'extensionkey = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($extensionKey, 'tx_ter_extensions')
);
return (int)$versionCounter;
}
/**
* @param array $extData
*
* @return void
*/
public function createExtension($extData)
{
$insertExtension = array(
'pid' => $this->pid,
'ext_key' => $extData['extensionkey'],
'last_upload' => 0,
'versions' => 0,
'last_version' => 0,
'frontend_user' => $extData['ownerusername'],
'crdate' => $extData['crdate'],
'tstamp' => $extData['tstamp'],
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_terfe2_domain_model_extension', $insertExtension);
}
}
......@@ -64,7 +64,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\TerFe2\Task
];
// Register import all extensions
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\TerFe2\Task\ImportAllExtensionsTask::class] = [
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\TerFe2\Task\ImportAllExtensionKeysTask::class] = [
'extension' => 'ter_fe2',
'title' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xlf:tx_terfe2_task_importallextensionstask.name',
'description' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xlf:tx_terfe2_task_importallextensionstask.description',
......
Markdown is supported
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