Commit 79ad9d7b authored by Christoph Hofmann's avatar Christoph Hofmann

upgrade

parent 69d14155
......@@ -78,6 +78,7 @@ class MissingClean extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
public function execute() {
/** @var \TYPO3\CMS\Core\Resource\File $file */
/** @var \TYPO3\CMS\Core\Database\DatabaseConnection $db */
/** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */
$success = FALSE;
$this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$this->storageRepository = $this->objectManager->get('TYPO3\CMS\Core\Resource\StorageRepository');
......@@ -102,63 +103,130 @@ class MissingClean extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
. BackendUtility::deleteClause($table);
$messages = array();
$count = 0;
$msgs = array();
$cleaned = array();
foreach ($missingFiles as $missingFile) {
$count ++;
if ($count > 1) {
$count++;
if ($count > 50) {
break;
debug1('break;');
}
$file = $this->getFile($missingFile['uid'], $missingFile['storage'], $missingFile['identifier']);
$name = $file->getName();
//find all references
$table = 'sys_file_reference';
$resultSet = $db->exec_SELECTquery('*', $table,"table_local = 'sys_file' AND uid_local = " . $missingFile['uid']);
$sys_file_references = array();
if ($resultSet) {
while ($row = $resultSet->fetch_assoc()) {
$sys_file_references[$row['uid']] = $row;
$storageUid = $missingFile['storage'];
$storage = $this->storageRepository->findByUid($storageUid); // get file storage with uid 1 (this should by default point to your fileadmin/ directory)
$conf = $storage->getConfiguration();
$fileName = GeneralUtility::getFileAbsFileName($conf['basePath']).ltrim($missingFile['identifier'],"\\\/");
if (!file_exists($fileName)) {
$file = $this->getFile($missingFile['uid'], $missingFile['storage'], $missingFile['identifier']);
if (!is_null($file)) {
$name = $file->getName();
}
} else {
debug1($db->debug_lastBuiltQuery);
}
$clean = true;
foreach( $sys_file_references as $fileref) {
if ($this->isImportantFileRef($fileref)) {
$clean = false;
$name = $missingFile['identifier'];
//find all references
$table = 'sys_file_reference';
$resultSet = $db->exec_SELECTquery('*', $table, "table_local = 'sys_file' AND uid_local = " . $missingFile['uid']);
$sys_file_references = array();
if ($resultSet) {
while ($row = $resultSet->fetch_assoc()) {
$sys_file_references[$row['uid']] = $row;
}
} else {
debug1($db->debug_lastBuiltQuery);
}
}
if ($clean) {
debug1('-------------clean--------------------------');
$this->deleteEntry($missingFile['uid'],'sys_file');
$this->deleteReference($missingFile['uid']);
$this->deleteProcessedfile($missingFile['uid']);
debug1($missingFile);
//processed file
//'sys_file_processedfile' $missingFile['uid']
} else {
//debug1($sys_file_references);
foreach( $sys_file_references as $fileref) {
if ($fileref['deleted'] != 1 && $fileref['hidden'] != 1 ) {
debug1($fileref);
$pid = $this->getPid($fileref['tablenames'], $fileref['uid_foreign']);
$messages[] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
$name . " in table :" . $fileref['tablenames'] . " in page:" . $pid . " uid:" . $fileref['uid_foreign'],
'Important Missing file', // the header is optional
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, // the severity is optional as well and defaults to \TYPO3\CMS\Core\Messaging\FlashMessage::OK
TRUE // optional, whether the message should be stored in the session or only in the \TYPO3\CMS\Core\Messaging\FlashMessageQueue object (default is FALSE)
);
$clean = true;
foreach ($sys_file_references as $key=>$fileref) {
if ($this->isImportantFileRef($fileref)) {
$clean = false;
$sys_file_references[$key]['toDelete']= 0;
} else {
$sys_file_references[$key]['toDelete']= 1;
unset($sys_file_references[$key]);
}
}
$count1 = 0;
if ($clean) {
debug1('-------------clean--------------------------');
$this->deleteEntry($missingFile['uid'], 'sys_file');
$this->deleteReference($missingFile['uid']);
$this->deleteProcessedfile($missingFile['uid']);
debug1($missingFile);
//processed file
//'sys_file_processedfile' $missingFile['uid']
$cleaned[] = $missingFile['identifier'];
} else {
//debug1($sys_file_references);
foreach ($sys_file_references as $fileref) {
if ($fileref['deleted'] != 1 && $fileref['hidden'] != 1) {
// debug1($missingFile);
$pid = $this->getPid($fileref['tablenames'], $fileref['uid_foreign']);
if (strlen($name)) {
$msg = array();
$msg['name'] = $name;
$msg['table'] = $fileref['tablenames'];
$msg['pid'] = $pid;
$msg['uid'] = $fileref['uid_foreign'];
$msgs[$missingFile['identifier_hash']][] = $msg;
} else {
$messages[] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
$name . " in table :" . $fileref['tablenames'] . " in page:" . $pid . " uid:" . $fileref['uid_foreign'],
'Important Missing file', // the header is optional
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, // the severity is optional as well and defaults to \TYPO3\CMS\Core\Messaging\FlashMessage::OK
TRUE // optional, whether the message should be stored in the session or only in the \TYPO3\CMS\Core\Messaging\FlashMessageQueue object (default is FALSE)
);
}
}
}
}
}
$flashMessageService = $this->objectManager->get(
\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
$messageQueue = $flashMessageService->getMessageQueueByIdentifier();
foreach ($messages as $message) {
$messageQueue->addMessage($message);
}
$flashMessageService = $this->objectManager->get(
\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
$messageQueue = $flashMessageService->getMessageQueueByIdentifier();
foreach ($messages as $message) {
$messageQueue->addMessage($message);
}
foreach ($msgs as $hash => $msg) {
$name = '';
$msgout = '';
foreach ($msg as $ms) {
$name = $ms ['name'];
$msgout .= "page:".$ms['pid']." table:".$ms['table']." uid:".$ms[uid]."; ";
}
//$msgout = "file:".$file." ".$msgout;
$messageQueue->addMessage(
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
$msgout ,
'Important Missing file:'.$name, // the header is optional
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, // the severity is optional as well and defaults to \TYPO3\CMS\Core\Messaging\FlashMessage::OK
TRUE // optional, whether the message should be stored in the session or only in the \TYPO3\CMS\Core\Messaging\FlashMessageQueue object (default is FALSE)
)
);
}
if (count($cleaned)>0) {
$msgout = '';
foreach ($cleaned as $file) {
$msgout.=$file.', ';
}
$messageQueue->addMessage(
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
$msgout ,
'The frgments of the following files are cleaned', // the header is optional
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, // the severity is optional as well and defaults to \TYPO3\CMS\Core\Messaging\FlashMessage::OK
TRUE // optional, whether the message should be stored in the session or only in the \TYPO3\CMS\Core\Messaging\FlashMessageQueue object (default is FALSE)
)
);
}
return TRUE;
......@@ -229,7 +297,7 @@ class MissingClean extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
// pid is deleted or hidden
$ret = true;
debug1('--------isImportantFileRef----------');
if ($fileRef['hidden'] == 1 || $fileRef['deleted'] == 1) {
debug1('file is deleted ----------------------------------------------');
if (!$this->pidExists($fileRef['pid'])) {
......@@ -243,10 +311,14 @@ class MissingClean extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
$ret = false;
}
if (in_array($fileRef['tablenames'],$this->ignoreTables)) {
$ret = false;
}
if ($fileRef['tablenames'] == 'sys_file_collection') {
debug1('----------------sys_file_collection----------------------------');
$ret = false;
......@@ -265,16 +337,19 @@ class MissingClean extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
$table = $fileRef['tablenames'];
$db = $GLOBALS['TYPO3_DB'];
$resultSet = $db->exec_SELECTquery('*', $table,"uid = ". intval($fileRef['uid_foreign']) );
$rows= array();
if ($resultSet) {
while ($row = $resultSet->fetch_assoc()) {
$rows[] = $row;
if ($row['hidden'] == 1 || $row['deleted'] == 1) {
$ret = false;
}
break;
}
}
debug1('------------------');
debug1($row);
if (count($rows)== 0) {
$ret = false;
}
$db->sql_free_result($resultSet);
return $ret;
}
......@@ -465,7 +540,16 @@ class MissingClean extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
function getFile ($uid, $storageUid, $identifier) {
/** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */
$storage = $this->storageRepository->findByUid($storageUid); // get file storage with uid 1 (this should by default point to your fileadmin/ directory)
$file = $storage->getFile($identifier);
try {
debug1('error');
$file = $storage->getFile($identifier);
debug1('error2');
} catch (Exception $e) {
echo 'Exception abgefangen: ', $e->getMessage(), "\n";
return NULL;
}
// throws an error if file is missing
return $file;
......
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