本文整理汇总了PHP中PublicFileManager::fileExists方法的典型用法代码示例。如果您正苦于以下问题:PHP PublicFileManager::fileExists方法的具体用法?PHP PublicFileManager::fileExists怎么用?PHP PublicFileManager::fileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PublicFileManager
的用法示例。
在下文中一共展示了PublicFileManager::fileExists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: localizeArticleCoverImages
/**
* Localize article cover images.
* @return boolean True indicates success.
*/
function localizeArticleCoverImages()
{
$articleDao = DAORegistry::getDAO('ArticleDAO');
$publicFileManager = new PublicFileManager();
// remove strange old cover images with array values in the DB - from 3.alpha or 3.beta?
$articleDao->update('DELETE FROM submission_settings WHERE setting_name = \'coverImage\' AND setting_type = \'object\'');
// remove empty 3.0 cover images
$articleDao->update('DELETE FROM submission_settings WHERE setting_name = \'coverImage\' AND locale = \'\' AND setting_value = \'\'');
$articleDao->update('DELETE FROM submission_settings WHERE setting_name = \'coverImageAltText\' AND locale = \'\' AND setting_value = \'\'');
// get cover image duplicates, from 2.4.x and 3.0
$result = $articleDao->retrieve('SELECT DISTINCT ss1.submission_id, ss1.setting_value, s.context_id
FROM submission_settings ss1
LEFT JOIN submissions s ON (s.submission_id = ss1.submission_id)
JOIN submission_settings ss2 ON (ss2.submission_id = ss1.submission_id AND ss2.setting_name = \'coverImage\')
WHERE ss1.setting_name = \'fileName\'');
// remove the old 2.4.x cover images, for which a new cover image exists
while (!$result->EOF) {
$row = $result->GetRowAssoc(false);
$submissionId = $row['submission_id'];
$oldFileName = $row['setting_value'];
if ($publicFileManager->fileExists($publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $row['context_id']) . '/' . $oldFileName)) {
$publicFileManager->removeJournalFile($row['journal_id'], $oldFileName);
}
$articleDao->update('DELETE FROM submission_settings WHERE submission_id = ? AND setting_name = \'fileName\' AND setting_value = ?', array((int) $submissionId, $oldFileName));
$result->MoveNext();
}
$result->Close();
// retrieve names for unlocalized article cover images
$result = $articleDao->retrieve('SELECT ss.submission_id, ss.setting_value, j.journal_id, j.primary_locale
FROM submission_settings ss, submissions s, journals j
WHERE ss.setting_name = \'coverImage\' AND ss.locale = \'\'
AND s.submission_id = ss.submission_id AND j.journal_id = s.context_id');
// for all unlocalized article cover images
// rename (copy + remove) the cover images files in the public folder,
// considereing the locale (using the journal primary locale)
while (!$result->EOF) {
$row = $result->GetRowAssoc(false);
$oldFileName = $row['setting_value'];
$newFileName = str_replace('.', '_' . $row['primary_locale'] . '.', $oldFileName);
if ($publicFileManager->fileExists($publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $row['journal_id']) . '/' . $oldFileName)) {
$publicFileManager->copyJournalFile($row['journal_id'], $publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $row['journal_id']) . '/' . $oldFileName, $newFileName);
$publicFileManager->removeJournalFile($row['journal_id'], $oldFileName);
}
$result->MoveNext();
}
$result->Close();
$driver = $articleDao->getDriver();
switch ($driver) {
case 'mysql':
case 'mysqli':
// Update cover image names in the submission_settings table
$articleDao->update('UPDATE submission_settings ss, submissions s, journals j
SET ss.locale = j.primary_locale, ss.setting_value = CONCAT(LEFT( ss.setting_value, LOCATE(\'.\', ss.setting_value) - 1 ), \'_\', j.primary_locale, \'.\', SUBSTRING_INDEX(ss.setting_value,\'.\',-1))
WHERE ss.setting_name = \'coverImage\' AND ss.locale = \'\' AND s.submission_id = ss.submission_id AND j.journal_id = s.context_id');
// Update cover image alt texts in the submission_settings table
$articleDao->update('UPDATE submission_settings ss, submissions s, journals j
SET ss.locale = j.primary_locale
WHERE ss.setting_name = \'coverImageAltText\' AND ss.locale = \'\' AND s.submission_id = ss.submission_id AND j.journal_id = s.context_id');
break;
case 'postgres':
// Update cover image names in the submission_settings table
$articleDao->update('UPDATE submission_settings
SET locale = j.primary_locale, setting_value = REGEXP_REPLACE(submission_settings.setting_value, \'[\\.]\', CONCAT(\'_\', j.primary_locale, \'.\'))
FROM submissions s, journals j
WHERE submission_settings.setting_name = \'coverImage\' AND submission_settings.locale = \'\' AND s.submission_id = submission_settings.submission_id AND j.journal_id = s.context_id');
// Update cover image alt texts in the submission_settings table
$articleDao->update('UPDATE submission_settings
SET locale = j.primary_locale
FROM submissions s, journals j
WHERE submission_settings.setting_name = \'coverImageAltText\' AND submission_settings.locale = \'\' AND s.submission_id = submission_settings.submission_id AND j.journal_id = s.context_id');
break;
default:
fatalError('Unknown database type!');
}
$articleDao->flushCache();
return true;
}