Skip to content

Commit

Permalink
Merge pull request #481 from kitodo/fix-472
Browse files Browse the repository at this point in the history
Check for non-existing and empty "document_format"
  • Loading branch information
sebastian-meyer committed Feb 18, 2020
2 parents c20ef5d + e1dd24f commit 82f16d7
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions class.ext_update.php
Expand Up @@ -375,8 +375,9 @@ protected function doSolariumSolrUpdate()
$this->content .= Helper::renderFlashMessages();
}

protected function hasNoFormatForDocument()
protected function hasNoFormatForDocument($checkStructureOnly = false)
{
// Check if column "document_format" exists.
$database = $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname'];
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'COLUMN_NAME',
Expand All @@ -385,31 +386,44 @@ protected function hasNoFormatForDocument()
);
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
if ($resArray['COLUMN_NAME'] == 'document_format') {
return false;
if ($checkStructureOnly) {
return false;
}
// Check if column has empty fields.
$result2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid',
'tx_dlf_documents',
'document_format="" OR document_format IS NULL'
);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result2) == 0) {
return false;
}
}
}
return true;
}

protected function updateDocumentAddFormat()
{
$sqlQuery = 'ALTER TABLE tx_dlf_documents ADD COLUMN document_format varchar(100) DEFAULT "" NOT NULL;';
$result = $GLOBALS['TYPO3_DB']->sql_query($sqlQuery);
if ($result) {
Helper::addMessage(
$GLOBALS['LANG']->getLL('update.documentAddFormatOkay', true),
$GLOBALS['LANG']->getLL('update.documentAddFormat', true),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK
);
$this->content .= Helper::renderFlashMessages();
} else {
Helper::addMessage(
$GLOBALS['LANG']->getLL('update.documentAddFormatNotOkay', true),
$GLOBALS['LANG']->getLL('update.documentAddFormat', true),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
);
$this->content .= Helper::renderFlashMessages();
return;
if ($this->hasNoFormatForDocument(true)) {
$sqlQuery = 'ALTER TABLE tx_dlf_documents ADD COLUMN document_format varchar(100) DEFAULT "" NOT NULL;';
$result = $GLOBALS['TYPO3_DB']->sql_query($sqlQuery);
if ($result) {
Helper::addMessage(
$GLOBALS['LANG']->getLL('update.documentAddFormatOkay', true),
$GLOBALS['LANG']->getLL('update.documentAddFormat', true),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK
);
$this->content .= Helper::renderFlashMessages();
} else {
Helper::addMessage(
$GLOBALS['LANG']->getLL('update.documentAddFormatNotOkay', true),
$GLOBALS['LANG']->getLL('update.documentAddFormat', true),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
);
$this->content .= Helper::renderFlashMessages();
return;
}
}
$sqlQuery = 'UPDATE `tx_dlf_documents` SET `document_format`="METS" WHERE `document_format` IS NULL OR `document_format`="";';
$result = $GLOBALS['TYPO3_DB']->sql_query($sqlQuery);
Expand Down

0 comments on commit 82f16d7

Please sign in to comment.