Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/categories/categories_event_handler.php
Show First 20 Lines • Show All 2437 Lines • ▼ Show 20 Line(s) | |||||
WHERE CONCAT(\'/\', c.Template, \'.tpl\') = CONCAT( tf.FilePath, \'/\', tf.FileName ) AND (c.ThemeId = t.ThemeId) | WHERE CONCAT(\'/\', c.Template, \'.tpl\') = CONCAT( tf.FilePath, \'/\', tf.FileName ) AND (c.ThemeId = t.ThemeId) | ||||
) = 0 '; | ) = 0 '; | ||||
$files = $this->Conn->Query($sql, 'Path'); | $files = $this->Conn->Query($sql, 'Path'); | ||||
if ( !$files ) { | if ( !$files ) { | ||||
// all possible pages are already created | // all possible pages are already created | ||||
return; | return; | ||||
} | } | ||||
$files = $this->sortByDependencies($files); | |||||
kUtil::setResourceLimit(); | kUtil::setResourceLimit(); | ||||
/** @var CategoriesItem $dummy */ | /** @var CategoriesItem $dummy */ | ||||
$dummy = $this->Application->recallObject($event->Prefix . '.rebuild', NULL, Array ('skip_autoload' => true)); | $dummy = $this->Application->recallObject($event->Prefix . '.rebuild', NULL, Array ('skip_autoload' => true)); | ||||
$error_count = 0; | $error_count = 0; | ||||
foreach ($files as $a_file => $file_info) { | foreach ($files as $a_file => $file_info) { | ||||
$status = $this->_prepareAutoPage($dummy, $a_file, $file_info['ThemeId'], SMS_MODE_FORCE, unserialize($file_info['FileMetaInfo'])); // create system page | $status = $this->_prepareAutoPage($dummy, $a_file, $file_info['ThemeId'], SMS_MODE_FORCE, unserialize($file_info['FileMetaInfo'])); // create system page | ||||
Show All 13 Lines | |||||
if ( $error_count ) { | if ( $error_count ) { | ||||
// allow user to review error after structure page creation | // allow user to review error after structure page creation | ||||
$event->MasterEvent->redirect = false; | $event->MasterEvent->redirect = false; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Sort structure files array by dependencies. | |||||
* | |||||
* @param array $files Files. | |||||
* | |||||
* @return array | |||||
*/ | |||||
protected function sortByDependencies(array $files) | |||||
{ | |||||
foreach ( $files as $template => $data ) { | |||||
$meta = unserialize($data['FileMetaInfo']); | |||||
$section = isset($meta['section']) ? $meta['section'] : ''; | |||||
$page_name = isset($meta['name']) ? $meta['name'] : '_Auto: ' . $template; | |||||
$files[$template]['sort_key'] = substr_count(($section ? $section . '||' : '') . $page_name, '||'); | |||||
} | |||||
uasort($files, array($this, 'compareSMSTemplates')); | |||||
return $files; | |||||
} | |||||
/** | |||||
* Files array comparing. | |||||
* | |||||
* @param array $sms_template_a First item. | |||||
* @param array $sms_template_b Second item. | |||||
* | |||||
* @return integer | |||||
*/ | |||||
public function compareSMSTemplates(array $sms_template_a, array $sms_template_b) | |||||
{ | |||||
if ( $sms_template_a['sort_key'] == $sms_template_b['sort_key'] ) { | |||||
return 0; | |||||
} | |||||
return $sms_template_a['sort_key'] < $sms_template_b['sort_key'] ? -1 : 1; | |||||
} | |||||
/** | |||||
* Processes OnMassMoveUp, OnMassMoveDown events | * Processes OnMassMoveUp, OnMassMoveDown events | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnChangePriority($event) | function OnChangePriority($event) | ||||
{ | { | ||||
$this->Application->SetVar('priority_prefix', $event->getPrefixSpecial()); | $this->Application->SetVar('priority_prefix', $event->getPrefixSpecial()); | ||||
$event->CallSubEvent('priority:' . $event->Name); | $event->CallSubEvent('priority:' . $event->Name); | ||||
▲ Show 20 Lines • Show All 752 Lines • Show Last 20 Lines |