public function sync()
{
if (!$this->blnIsDbAssisted) {
return '';
}
$this->import('BackendUser', 'User');
$this->loadLanguageFile('tl_files');
// Check the permission to synchronize
if (!$this->User->hasAccess('f6', 'fop')) {
throw new AccessDeniedException('Not enough permissions to synchronize the file system.');
}
// Synchronize
$strLog = \Dbafs::syncFiles();
// Show the results
$arrMessages = array();
$arrCounts = array('Added' => 0, 'Changed' => 0, 'Unchanged' => 0, 'Moved' => 0, 'Deleted' => 0);
// Read the log file
$fh = fopen(TL_ROOT . '/' . $strLog, 'rb');
while (($buffer = fgets($fh)) !== false) {
list($type, $file) = explode('] ', trim(substr($buffer, 1)), 2);
// Add a message depending on the type
switch ($type) {
case 'Added':
$arrMessages[] = '<p class="tl_new">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncAdded'], \StringUtil::specialchars($file)) . '</p>';
break;
case 'Changed':
$arrMessages[] = '<p class="tl_info">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncChanged'], \StringUtil::specialchars($file)) . '</p>';
break;
case 'Unchanged':
$arrMessages[] = '<p class="tl_confirm hidden">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncUnchanged'], \StringUtil::specialchars($file)) . '</p>';
break;
case 'Moved':
list($source, $target) = explode(' to ', $file, 2);
$arrMessages[] = '<p class="tl_info">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncMoved'], \StringUtil::specialchars($source), \StringUtil::specialchars($target)) . '</p>';
break;
case 'Deleted':
$arrMessages[] = '<p class="tl_error">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncDeleted'], \StringUtil::specialchars($file)) . '</p>';
break;
}
++$arrCounts[$type];
}
// Close the log file
unset($buffer);
fclose($fh);
// Confirm
\Message::addConfirmation($GLOBALS['TL_LANG']['tl_files']['syncComplete']);
$return = '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>
' . \Message::generate() . '
<div id="sync-results">
<p class="left">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncResult'], \System::getFormattedNumber($arrCounts['Added'], 0), \System::getFormattedNumber($arrCounts['Changed'], 0), \System::getFormattedNumber($arrCounts['Unchanged'], 0), \System::getFormattedNumber($arrCounts['Moved'], 0), \System::getFormattedNumber($arrCounts['Deleted'], 0)) . '</p>
<p class="right"><input type="checkbox" id="show-hidden" class="tl_checkbox" onclick="Backend.toggleUnchanged()"> <label for="show-hidden">' . $GLOBALS['TL_LANG']['tl_files']['syncShowUnchanged'] . '</label></p>
</div>
<div class="tl_message" id="result-list">';
// Add the messages
foreach ($arrMessages as $strMessage) {
$return .= "\n " . $strMessage;
}
$return .= '
</div>
<div class="tl_submit_container">
<a href="' . $this->getReferer(true) . '" class="tl_submit" style="display:inline-block">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>
</div>
';
return $return;
}