Changeset View
Changeset View
Standalone View
Standalone View
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, '||'); | |||||
alex: Please replace with for increased clarity:
```
lang=php
$section = isset($meta['section']) ? | |||||
Not Done Reply
Sorting by category path gives nothing because categories with large depth, but the short name would be created first. Instead, we should create parent categories first and only then sub-categories. alex: # don't add `$section . '||'`, when `$section` is empty
# wrap with `substr_count(..., '||')`… | |||||
} | |||||
uasort($files, array($this, 'compareSMSTemplates')); | |||||
return $files; | |||||
} | |||||
/** | |||||
* Files array comparing. | |||||
Not Done Replyreplace / with . typo alex: replace `/` with `.`
---
typo | |||||
* | |||||
* @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) | |||||
Not Done ReplyPlease:
alex: Please:
# rename `sortCompare` into `compareSMSTemplates`
# rename `$a` into `$sms_template_a`… | |||||
{ | |||||
if ( $sms_template_a['sort_key'] == $sms_template_b['sort_key'] ) { | |||||
Not Done ReplyBring back the previous code version. alex: Bring back the previous code version. | |||||
return 0; | |||||
} | |||||
return $sms_template_a['sort_key'] < $sms_template_b['sort_key'] ? -1 : 1; | |||||
} | |||||
/** | |||||
* Processes OnMassMoveUp, OnMassMoveDown events | * Processes OnMassMoveUp, OnMassMoveDown events | ||||
Not Done Replyreplace with: return strcmp($sms_template_a['sort_key'], $sms_template_b['sort_key']); there is dedicated function for binary-safe string comparison alex: replace with:
```
lang=php
return strcmp($sms_template_a['sort_key'], $sms_template_b… | |||||
* | * | ||||
* @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 751 Lines • Show Last 20 Lines |
Please replace with for increased clarity:
Code worked before as well, but since we only have 2 parts to combine, then using implode doesn't really help.