Skip to content

Commit

Permalink
[CLEANUP] Optimize scheduler task to be run in CLI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bmack committed Jan 13, 2014
1 parent 0eb588c commit 7ccd7af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Classes/Task/MigrateDamCategoryRelationsTask.php
Expand Up @@ -160,7 +160,7 @@ protected function getAllMigratedDamRecords() {

$select = 'uid, _migrateddamuid AS damuid';
$from = 'sys_file';
$where = '_migrateddamuid>0 AND deleted=0';
$where = '_migrateddamuid>0';
$index = 'damuid';

$migratedRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($select,$from,$where,'','','',$index);
Expand Down Expand Up @@ -251,4 +251,4 @@ protected function increaseCategoriesFieldOfFile($fileUid) {

$GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_file', $where, $updateValues);
}
}
}
4 changes: 2 additions & 2 deletions Classes/Task/MigrateRelationsTask.php
Expand Up @@ -46,7 +46,7 @@ public function execute() {
$falRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'uid, _migrateddamuid AS damuid',
'sys_file',
'_migrateddamuid>0 AND deleted=0',
'_migrateddamuid>0',
'', // group by
'', // order by
'', // limit
Expand Down Expand Up @@ -122,4 +122,4 @@ public function execute() {
return TRUE;
}

}
}
23 changes: 14 additions & 9 deletions Classes/Task/MigrateTask.php
Expand Up @@ -55,7 +55,7 @@ public function execute() {
$migratedRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'uid, _migrateddamuid AS damuid',
'sys_file',
'_migrateddamuid>0 AND deleted=0',
'_migrateddamuid>0',
'', // group by
'', // order by
'', // limit
Expand Down Expand Up @@ -96,6 +96,7 @@ public function execute() {
// right now we only support files in fileadmin/
if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($fileIdentifier, 'fileadmin/') === TRUE) {
// strip away the "fileadmin/" prefix
echo 'Indexing ' . $fileIdentifier . CRLF;
$fullFileName = substr($fileIdentifier, 10);

// check if the DAM record is already indexed for FAL (based on the filename)
Expand All @@ -105,7 +106,7 @@ public function execute() {
// file not found jump to next file
continue;
} catch(\Exception $e) {
var_dump($e);
echo 'File not found: ' . $fullFileName . CRLF;
}

if ($fileObject instanceof \TYPO3\CMS\Core\Resource\File) {
Expand All @@ -121,10 +122,12 @@ public function execute() {
$updateData['location_country'] = $damRecord['location_country'];
}

$fileObject->updateProperties($updateData);
$fileRepository->update($fileObject);

#$uid = $fileObject->getUid();
$uid = $fileObject->getUid();
$GLOBALS['TYPO3_DB']->exec_UPDATEquery(
'sys_file',
'uid=' . $uid,
$updateData
);
$migratedFiles++;


Expand All @@ -144,11 +147,13 @@ public function execute() {
$message = 'All files have been migrated.';
}

$messageObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, $headline);
\TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($messageObject);
if (!TYPO3_cliMode) {
$messageObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, $headline);
\TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($messageObject);
}

// it was always a success
return TRUE;
}

}
}

0 comments on commit 7ccd7af

Please sign in to comment.