Index: branches/5.2.x/core/kernel/db/db_tag_processor.php
===================================================================
diff -u -N -r14865 -r14870
--- branches/5.2.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 14865)
+++ branches/5.2.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 14870)
@@ -1,6 +1,6 @@
PredefinedOptions($params);
}
- function Format($params)
+ function Format($params, $object = null)
{
$field = $this->SelectParam($params, 'name,field');
- $object =& $this->getObject($params);
- $options = $object->GetFieldOptions($field);
+ if ( !isset($object) ) {
+ $object =& $this->getObject($params);
+ /* @var $object kDBItem */
+ }
+
+ $options = $object->GetFieldOptions($field);
$format = $options[$this->SelectParam($params, 'input_format') ? 'input_format' : 'format'];
$formatter_class = array_key_exists('formatter', $options) ? $options['formatter'] : false;
@@ -2317,31 +2321,9 @@
function SearchFormat($params)
{
- $field = $params['field'];
$object =& $this->GetList($params);
- $options = $object->GetFieldOptions($field);
- $format = $options[ $this->SelectParam($params, 'input_format') ? 'input_format' : 'format' ];
- $formatter_class = array_key_exists('formatter', $options) ? $options['formatter'] : false;
-
- if ($formatter_class) {
- $formatter =& $this->Application->recallObject($formatter_class);
- /* @var $formatter kFormatter */
-
- $human_format = array_key_exists('human', $params) ? $params['human'] : false;
- $edit_size = array_key_exists('edit_size', $params) ? $params['edit_size'] : false;
- $sample = array_key_exists('sample', $params) ? $params['sample'] : false;
-
- if ($sample) {
- return $formatter->GetSample($field, $options, $object);
- }
- elseif ($human_format || $edit_size) {
- $format = $formatter->HumanFormat($format);
- return $edit_size ? strlen($format) : $format;
- }
- }
-
- return $format;
+ return $this->Format($params, $object);
}
/**
Index: branches/5.2.x/core/units/mailing_lists/mailing_list_tp.php
===================================================================
diff -u -N -r14244 -r14870
--- branches/5.2.x/core/units/mailing_lists/mailing_list_tp.php (.../mailing_list_tp.php) (revision 14244)
+++ branches/5.2.x/core/units/mailing_lists/mailing_list_tp.php (.../mailing_list_tp.php) (revision 14870)
@@ -1,6 +1,6 @@
getObject($params);
/* @var $object kDBItem */
- $recipients = explode(';', $object->GetDBField('To'));
-
- // 1. group recipients by types
- $recipients_grouped = Array ();
- foreach ($recipients as $recipient) {
- if (strpos($recipient, '_') !== false) {
- list ($recipient_type, $recipient_id) = explode('_', $recipient);
- }
- else {
- $recipient_type = 'direct';
- $recipient_id = $recipient;
- }
-
- if (!array_key_exists($recipient_type, $recipients_grouped)) {
- $recipients_grouped[$recipient_type] = Array ();
- }
-
- $recipients_grouped[$recipient_type][] = $recipient_id;
- }
-
$mailing_list_helper =& $this->Application->recallObject('MailingListHelper');
/* @var $mailing_list_helper MailingListHelper */
// for each group convert ids to names
- $recpient_names = Array ();
+ $recipient_names = Array ();
+ $recipients_grouped = $mailing_list_helper->groupRecipientsByType(explode(';', $object->GetDBField('To')));
+
foreach ($recipients_grouped as $recipient_type => $group_recipients) {
- $recpient_names = array_merge($recpient_names, $mailing_list_helper->getRecipientNames($recipient_type, $group_recipients));
+ $recipient_names = array_merge($recipient_names, $mailing_list_helper->getRecipientNames($recipient_type, $group_recipients));
}
$ret = '';
- $recipient_count = count($recpient_names);
+ $recipient_count = count($recipient_names);
$block_params = $this->prepareTagParams($params);
$block_params['name'] = $params['render_as'];
- foreach ($recpient_names as $recipient_index => $recipient_name) {
+ foreach ($recipient_names as $recipient_index => $recipient_name) {
$block_params['recipient_name'] = $recipient_name;
$block_params['not_last'] = $recipient_index < $recipient_count - 1;
Index: branches/5.2.x/core/kernel/globals.php
===================================================================
diff -u -N -r14868 -r14870
--- branches/5.2.x/core/kernel/globals.php (.../globals.php) (revision 14868)
+++ branches/5.2.x/core/kernel/globals.php (.../globals.php) (revision 14870)
@@ -1,6 +1,6 @@
\n") {
+ if ( $contents && $contents[0] == '<' . '?' . 'php die() ?' . ">\n" ) {
// format of "config.php" file before 5.1.0 version
array_shift($contents);
@@ -155,7 +155,7 @@
$_CONFIG = Array ();
require($file);
- if ($parse_section) {
+ if ( $parse_section ) {
if ( isset($_CONFIG['Database']['LoadBalancing']) && $_CONFIG['Database']['LoadBalancing'] ) {
require FULL_PATH . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'db_servers.php';
}
@@ -447,14 +447,7 @@
*/
public static function fputcsv($filePointer, $data, $delimiter = ',', $enclosure = '"', $recordSeparator = "\r\n")
{
- foreach($data as $field_index => $field_value) {
- // replaces an enclosure with two enclosures
- $data[$field_index] = str_replace($enclosure, $enclosure.$enclosure, $field_value);
- }
-
- $line = $enclosure.implode($enclosure.$delimiter.$enclosure, $data).$enclosure.$recordSeparator;
- $line = preg_replace('/'.preg_quote($enclosure, '/').'([0-9\.]+)'.preg_quote($enclosure, '/').'/', '$1', $line);
- fwrite($filePointer, $line);
+ fwrite($filePointer, self::getcsvline($data, $delimiter, $enclosure, $recordSeparator));
}
/**
@@ -563,7 +556,7 @@
return ($ip >= $from && $ip <= $to);
}
elseif (strpos($network, '/') !== false) {
- // sigle subnet specified
+ // single subnet specified
$ip_arr = explode('/', $network);
if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)) {
Index: branches/5.2.x/core/units/helpers/csv_helper.php
===================================================================
diff -u -N -r14585 -r14870
--- branches/5.2.x/core/units/helpers/csv_helper.php (.../csv_helper.php) (revision 14585)
+++ branches/5.2.x/core/units/helpers/csv_helper.php (.../csv_helper.php) (revision 14870)
@@ -1,6 +1,6 @@
Application->RecallVar('export_rand');
$get_rand = $this->Application->GetVar('export_rand');
- if($export_data && $export_rand == $get_rand) {
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
+
+ if ( $export_data && $export_rand == $get_rand ) {
$export_data = unserialize($export_data);
$first_step = false;
}
else {
// first step
- $export_data = Array();
+ $export_data = Array ();
$export_data['prefix'] = $this->PrefixSpecial;
$export_data['grid'] = $this->grid;
- $export_data['file_name'] = EXPORT_PATH.'/'.$this->ValidateFileName(EXPORT_PATH, 'export_'.$export_data['prefix'].'.csv');
+ $export_data['file_name'] = EXPORT_PATH . '/' . $file_helper->ensureUniqueFilename(EXPORT_PATH, 'export_' . $export_data['prefix'] . '.csv');
$export_data['step'] = EXPORT_STEP;
$export_data['delimiter'] = $this->delimiter_mapping[(int)$this->Application->ConfigValue('CSVExportDelimiter')];
$export_data['enclosure'] = $this->enclosure_mapping[(int)$this->Application->ConfigValue('CSVExportEnclosure')];
@@ -50,74 +53,74 @@
$lang_object =& $this->Application->recallObject('lang.current');
/* @var $lang_object LanguagesItem */
- $export_data['source_encoding'] = strtoupper( $lang_object->GetDBField('Charset') );
+
+ $export_data['source_encoding'] = strtoupper($lang_object->GetDBField('Charset'));
$export_data['encoding'] = $this->Application->ConfigValue('CSVExportEncoding') ? false : 'UTF-16LE';
$this->Application->StoreVar('export_rand', $get_rand);
$first_step = true;
}
- $file_helper =& $this->Application->recallObject('FileHelper');
- /* @var $file_helper FileHelper */
-
- $file_helper->CheckFolder( dirname($export_data['file_name']) );
-
$file = fopen($export_data['file_name'], $first_step ? 'w' : 'a');
$prefix_elems = preg_split('/\.|_/', $export_data['prefix'], 2);
$grids = $this->Application->getUnitOption($prefix_elems[0], 'Grids');
- $grid_config = $grids[ $export_data['grid'] ]['Fields'];
+ $grid_config = $grids[$export_data['grid']]['Fields'];
- $list_params = Array('per_page' => $export_data['step'], 'grid' => $export_data['grid']);
- $list =& $this->Application->recallObject(rtrim(implode('.', $prefix_elems), '.'), $prefix_elems[0].'_List', $list_params);
+ $list_params = Array ('per_page' => $export_data['step'], 'grid' => $export_data['grid']);
+ $list =& $this->Application->recallObject(rtrim(implode('.', $prefix_elems), '.'), $prefix_elems[0] . '_List', $list_params);
/* @var $list kDBList */
- $list->SetPage($export_data['page']);
+ $list->SetPage($export_data['page']);
$list->Query();
$list->GoFirst();
$picker_helper =& $this->Application->RecallObject('ColumnPickerHelper');
/* @var $picker_helper kColumnPickerHelper */
+
$picker_helper->ApplyPicker(rtrim(implode('.', $prefix_elems), '.'), $grid_config, $export_data['grid']);
- if($first_step) {
+ if ( $first_step ) {
// if UTF-16, write Unicode marker
- if($export_data['encoding'] == 'UTF-16LE') {
- fwrite($file, chr(0xFF).chr(0xFE));
+ if ( $export_data['encoding'] == 'UTF-16LE' ) {
+ fwrite($file, chr(0xFF) . chr(0xFE));
}
// inserting header line
- $headers = Array();
- foreach($grid_config as $field_name => $field_data) {
- $use_phrases = array_key_exists('use_phrases', $field_data) ? $field_data['use_phrases'] : 1;
- $header = $use_phrases ? $this->Application->Phrase( $field_data['title'] ) : $field_data['title'];
+ $headers = Array ();
+ foreach ($grid_config as $field_name => $field_data) {
+ $use_phrases = array_key_exists('use_phrases', $field_data) ? $field_data['use_phrases'] : true;
+ $field_title = isset($field_data['title']) ? $field_data['title'] : 'column:la_fld_' . $field_name;
+ $header = $use_phrases ? $this->Application->Phrase($field_title) : $field_title;
array_push($headers, $header);
}
+
$csv_line = kUtil::getcsvline($headers, $export_data['delimiter'], $export_data['enclosure'], $export_data['record_separator']);
- if($export_data['encoding']) {
+ if ( $export_data['encoding'] ) {
$csv_line = mb_convert_encoding($csv_line, $export_data['encoding'], $export_data['source_encoding']);
}
fwrite($file, $csv_line);
}
- while(!$list->EOL())
- {
- $data = Array();
- foreach($grid_config as $field_name => $field_data) {
- if(isset($field_data['export_field'])) {
+ while (!$list->EOL()) {
+ $data = Array ();
+ foreach ($grid_config as $field_name => $field_data) {
+ if ( isset($field_data['export_field']) ) {
$field_name = $field_data['export_field'];
}
$value = $list->GetField($field_name, isset($field_data['format']) ? $field_data['format'] : null);
$value = str_replace("\r\n", "\n", $value);
$value = str_replace("\r", "\n", $value);
array_push($data, $value);
}
- if($export_data['encoding'] == 'UTF-16LE') {
- fwrite($file, chr(0xFF).chr(0xFE));
+
+ if ( $export_data['encoding'] == 'UTF-16LE' ) {
+ fwrite($file, chr(0xFF) . chr(0xFE));
}
+
$csv_line = kUtil::getcsvline($data, $export_data['delimiter'], $export_data['enclosure'], $export_data['record_separator']);
- if($export_data['encoding']) {
+ if ( $export_data['encoding'] ) {
$csv_line = mb_convert_encoding($csv_line, $export_data['encoding'], $export_data['source_encoding']);
}
fwrite($file, $csv_line);
@@ -130,7 +133,7 @@
fclose($file);
- if ($records_processed >= $list->GetRecordsCount()) {
+ if ( $records_processed >= $list->GetRecordsCount() ) {
$this->Application->StoreVar('export_data', serialize($export_data));
$this->Application->Redirect($this->Application->GetVar('finish_template'));
}
@@ -141,30 +144,29 @@
$this->Application->StoreVar('export_data', serialize($export_data));
}
- function ValidateFileName($path, $name)
- {
- $parts = pathinfo($name);
- $ext = '.'.$parts['extension'];
- $filename = mb_substr($parts['basename'], 0, -mb_strlen($ext));
- $new_name = $filename.$ext;
- while ( file_exists($path.'/'.$new_name) )
- {
- if ( preg_match('/('.preg_quote($filename, '/').'_)([0-9]*)('.preg_quote($ext, '/').')/', $new_name, $regs) ) {
- $new_name = $regs[1].($regs[2]+1).$regs[3];
- }
- else {
- $new_name = $filename.'_1'.$ext;
- }
- }
- return $new_name;
- }
-
function ExportData($name)
{
$export_data = unserialize($this->Application->RecallVar('export_data'));
return isset($export_data[$name]) ? $export_data[$name] : false;
}
+ /**
+ * Returns prefix from request or from stored import/export data
+ *
+ * @param bool $is_import
+ * @return string
+ */
+ public function getPrefix($is_import = false)
+ {
+ $prefix = $this->Application->GetVar('PrefixSpecial');
+
+ if ( !$prefix ) {
+ return $is_import ? $this->ImportData('prefix') : $this->ExportData('prefix');
+ }
+
+ return $prefix;
+ }
+
function GetCSV()
{
kUtil::safeDefine('DBG_SKIP_REPORTING', 1);
Index: branches/5.2.x/core/units/category_items/category_items_dbitem.php
===================================================================
diff -u -N -r14628 -r14870
--- branches/5.2.x/core/units/category_items/category_items_dbitem.php (.../category_items_dbitem.php) (revision 14628)
+++ branches/5.2.x/core/units/category_items/category_items_dbitem.php (.../category_items_dbitem.php) (revision 14870)
@@ -1,6 +1,6 @@
getLinkedInfo();
Index: branches/5.2.x/core/units/helpers/mailing_list_helper.php
===================================================================
diff -u -N -r14861 -r14870
--- branches/5.2.x/core/units/helpers/mailing_list_helper.php (.../mailing_list_helper.php) (revision 14861)
+++ branches/5.2.x/core/units/helpers/mailing_list_helper.php (.../mailing_list_helper.php) (revision 14870)
@@ -1,6 +1,6 @@
groupRecipientsByType(explode(';', $fields_hash['To']));
- // 1. group recipients by types
+ foreach ($recipients_grouped as $recipient_type => $group_recipients) {
+ $recipient_emails = array_merge($recipient_emails, $this->_getRecipientEmails($recipient_type, $group_recipients));
+ }
+
+ $recipient_emails = array_unique($recipient_emails);
+
+ return Array (
+ 'ToParsed' => serialize($recipient_emails),
+ 'EmailsTotal' => count($recipient_emails),
+ );
+ }
+
+ /**
+ * Groups recipients by type
+ *
+ * @param Array $recipients
+ * @return Array
+ * @access public
+ */
+ public function groupRecipientsByType($recipients)
+ {
$recipients_grouped = Array ();
+
foreach ($recipients as $recipient) {
- if (strpos($recipient, '_') !== false) {
+ if ( strpos($recipient, '_') !== false ) {
list ($recipient_type, $recipient_id) = explode('_', $recipient);
}
else {
$recipient_type = 'direct';
$recipient_id = $recipient;
}
- if (!array_key_exists($recipient_type, $recipients_grouped)) {
+ if ( !array_key_exists($recipient_type, $recipients_grouped) ) {
$recipients_grouped[$recipient_type] = Array ();
}
$recipients_grouped[$recipient_type][] = $recipient_id;
}
- // for each group convert ids to names
- $recpient_emails = Array ();
- foreach ($recipients_grouped as $recipient_type => $group_recipients) {
- $recpient_emails = array_merge($recpient_emails, $this->_getRecipientEmails($recipient_type, $group_recipients));
- }
-
- $recpient_emails = array_unique($recpient_emails);
-
- return Array (
- 'ToParsed' => serialize($recpient_emails),
- 'EmailsTotal' => count($recpient_emails),
- );
+ return $recipients_grouped;
}
function _getRecipientEmails($recipient_type, $recipient_ids)
Index: branches/5.2.x/core/units/helpers/permissions_helper.php
===================================================================
diff -u -N -r14856 -r14870
--- branches/5.2.x/core/units/helpers/permissions_helper.php (.../permissions_helper.php) (revision 14856)
+++ branches/5.2.x/core/units/helpers/permissions_helper.php (.../permissions_helper.php) (revision 14870)
@@ -1,6 +1,6 @@
getEventParam('top_prefix');
- $pefix_type = ($top_prefix == $event->Prefix) ? 'self' : 'subitem';
+ $prefix_type = ($top_prefix == $event->Prefix) ? 'self' : 'subitem';
$perm_mapping = getArrayValue($perm_mapping, $event->Name);
- if (!$perm_mapping[$pefix_type]) {
+ if (!$perm_mapping[$prefix_type]) {
throw new Exception('Permission mappings not defined for event ' . $top_prefix . ' <- ' . $event->Prefix . ':' . $event->Name . '');
}
- if ($perm_mapping[$pefix_type] === true) {
+ if ($perm_mapping[$prefix_type] === true) {
// event is defined in mapping but is not checked by permissions
return true;
}
- return explode('|', $perm_mapping[$pefix_type]);
+ return explode('|', $perm_mapping[$prefix_type]);
}
/**
Index: branches/5.2.x/core/kernel/nparser/ntags.php
===================================================================
diff -u -N -r14244 -r14870
--- branches/5.2.x/core/kernel/nparser/ntags.php (.../ntags.php) (revision 14244)
+++ branches/5.2.x/core/kernel/nparser/ntags.php (.../ntags.php) (revision 14870)
@@ -1,6 +1,6 @@
AppendCheckCode($o, $tag);
+
+ return $o;
+ }
+
+ /**
+ * Adds check code to $o
+ *
+ * @param string $o
+ * @param Array $tag
+ * @return void
+ * @access protected
+ */
+ protected function AppendCheckCode(&$o, $tag)
+ {
$to_pass = $this->Parser->CompileParamsArray($tag['NP']);
+ $code = Array ();
$code[] = "\$_splited = \$_parser->SplitTag(array('tag'=>\"{$tag['NP']['check']}\", 'file'=>'{$tag['file']}', 'line'=>{$tag['line']}));";
$code[] = 'if ($_splited[\'prefix\'] == \'__auto__\') {$_splited[\'prefix\'] = $PrefixSpecial;}';
$code[] = '$_p_ =& $_parser->GetProcessor($_splited[\'prefix\']);';
- if (isset($tag['NP']['inverse']) || $this->_Inversed) {
+
+ if ( isset($tag['NP']['inverse']) || $this->_Inversed ) {
$code[] = "if (!\$_p_->ProcessParsedTag(\$_splited['name'], $to_pass, \$_splited['prefix'], '{$tag['file']}', {$tag['line']})) {";
}
else {
$code[] = "if (\$_p_->ProcessParsedTag(\$_splited['name'], $to_pass, \$_splited['prefix'], '{$tag['file']}', {$tag['line']})) {";
}
+
$this->AppendCode($o, $code);
- return $o;
}
function PassThrough(&$tag)
@@ -505,23 +522,11 @@
return '';
}
- $to_pass = $this->Parser->CompileParamsArray($tag['NP']);
-
$this->_elseIfCount++; // add same count of closing brackets in closing tag
$this->AppendCode($o, "} else {");
+ $this->AppendCheckCode($o, $tag);
- $code[] = "\$_splited = \$_parser->SplitTag(array('tag'=>\"{$tag['NP']['check']}\", 'file'=>'{$tag['file']}', 'line'=>{$tag['line']}));";
- $code[] = 'if ($_splited[\'prefix\'] == \'__auto__\') {$_splited[\'prefix\'] = $PrefixSpecial;}';
- $code[] = '$_p_ =& $_parser->GetProcessor($_splited[\'prefix\']);';
- if (isset($tag['NP']['inverse']) || $this->_Inversed) {
- $code[] = "if (!\$_p_->ProcessParsedTag(\$_splited['name'], $to_pass, \$_splited['prefix'], '{$tag['file']}', {$tag['line']})) {";
- }
- else {
- $code[] = "if (\$_p_->ProcessParsedTag(\$_splited['name'], $to_pass, \$_splited['prefix'], '{$tag['file']}', {$tag['line']})) {";
- }
- $this->AppendCode($o, $code);
-
$tag['processed'] = true;
}
return $o;
Index: branches/5.2.x/core/kernel/db/db_event_handler.php
===================================================================
diff -u -N -r14856 -r14870
--- branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14856)
+++ branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14870)
@@ -1,6 +1,6 @@
_update($event);
+
+ $event->SetRedirectParam('opener', 'u');
+ }
+
+ /**
+ * Updates data in database based on request
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function _update(kEvent &$event)
+ {
$object =& $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
@@ -1469,8 +1483,6 @@
}
}
}
-
- $event->SetRedirectParam('opener', 'u');
}
/**
@@ -1860,27 +1872,8 @@
return ;
}
- $object =& $event->getObject( Array ('skip_autoload' => true) );
- /* @var $object kDBItem */
-
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if ( $items_info ) {
- foreach ($items_info as $id => $field_values) {
- $object->Load($id);
- $object->SetFieldsFromHash($field_values);
- $this->customProcessing($event, 'before');
-
- if ( $object->Update($id) ) {
- $this->customProcessing($event, 'after');
- $event->status = kEvent::erSUCCESS;
- }
- else {
- $event->status = kEvent::erFAIL;
- $event->redirect = false;
- break;
- }
- }
- }
+ // don't just call OnUpdate event here, since it maybe overwritten to Front-End specific behavior
+ $this->_update($event);
}
/**
Index: branches/5.2.x/core/units/helpers/backup_helper.php
===================================================================
diff -u -N -r14707 -r14870
--- branches/5.2.x/core/units/helpers/backup_helper.php (.../backup_helper.php) (revision 14707)
+++ branches/5.2.x/core/units/helpers/backup_helper.php (.../backup_helper.php) (revision 14870)
@@ -357,13 +357,13 @@
}
/**
- * Run given schema sqls and return error, if any
+ * Adds table prefix to given sql set
*
- * @param $sql
- * @return string
+ * @param string $sql
+ * @return void
* @access protected
*/
- protected function runSchemaText($sql)
+ protected function addTablePrefix(&$sql)
{
$table_prefix = 'restore' . TABLE_PREFIX;
@@ -377,7 +377,19 @@
$sql = str_replace('CREATE TABLE ', 'CREATE TABLE IF NOT EXISTS ' . $table_prefix, $sql);
$sql = str_replace('DROP TABLE ', 'DROP TABLE IF EXISTS ' . $table_prefix, $sql);
+ }
+ /**
+ * Run given schema sqls and return error, if any
+ *
+ * @param $sql
+ * @return string
+ * @access protected
+ */
+ protected function runSchemaText($sql)
+ {
+ $this->addTablePrefix($sql);
+
$commands = explode("# --------------------------------------------------------", $sql);
if ( count($commands) > 0 ) {
@@ -412,18 +424,7 @@
$sql = $all_sqls[$line];
if ( strlen(trim($sql)) > 0 && substr($sql, 0, 1) != "#" ) {
- $table_prefix = 'restore' . TABLE_PREFIX;
-
- if ( strlen($table_prefix) > 0 ) {
- $replacements = Array ('INSERT INTO ', 'UPDATE ', 'ALTER TABLE ', 'DELETE FROM ', 'REPLACE INTO ');
-
- foreach ($replacements as $replacement) {
- $sql = str_replace($replacement, $replacement . $table_prefix, $sql);
- }
- }
-
- $sql = str_replace('CREATE TABLE ', 'CREATE TABLE IF NOT EXISTS ' . $table_prefix, $sql);
- $sql = str_replace('DROP TABLE ', 'DROP TABLE IF EXISTS ' . $table_prefix, $sql);
+ $this->addTablePrefix($sql);
$sql = trim($sql);
if ( strlen($sql) > 0 ) {
Index: branches/5.2.x/core/units/admin/admin_events_handler.php
===================================================================
diff -u -N -r14851 -r14870
--- branches/5.2.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 14851)
+++ branches/5.2.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 14870)
@@ -1,6 +1,6 @@
array('self' => true),
'OnClosePopup' => array('self' => true),
'OnSaveSetting' => array('self' => true),
- // export/import permissions is checked within events
- 'OnExportCSV' => Array('self' => true),
- 'OnGetCSV' => Array('self' => true),
- 'OnCSVImportBegin' => Array('self' => true),
- 'OnCSVImportStep' => Array('self' => true),
'OnDropTempTablesByWID' => Array('self' => true),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
@@ -51,7 +46,7 @@
'OnDeploy', 'OnRebuildThemes', 'OnCheckPrefixConfig', 'OnMemoryCacheGet', 'OnMemoryCacheSet'
);
- if (in_array($event->Name, $system_events)) {
+ if ( in_array($event->Name, $system_events) ) {
// events from "Tools -> System Tools" section are controlled via that section "edit" permission
$perm_value = /*$this->Application->isDebugMode() ||*/ $this->Application->CheckPermission($event->getSection() . '.edit');
}
@@ -69,32 +64,53 @@
'OnSqlQuery' => 'in-portal:sql_query.view',
);
- if (array_key_exists($event->Name, $tools_events)) {
+ if ( array_key_exists($event->Name, $tools_events) ) {
$perm_value = $this->Application->CheckPermission($tools_events[$event->Name]);
}
- if ($event->Name == 'OnSaveMenuFrameWidth') {
+ if ( $event->Name == 'OnSaveMenuFrameWidth' ) {
$perm_value = $this->Application->isAdminUser;
}
- if (isset($perm_value)) {
- $perm_helper =& $this->Application->recallObject('PermissionsHelper');
- /* @var $perm_helper kPermissionsHelper */
+ $perm_helper =& $this->Application->recallObject('PermissionsHelper');
+ /* @var $perm_helper kPermissionsHelper */
+ $csv_events = Array ('OnCSVImportBegin', 'OnCSVImportStep', 'OnExportCSV', 'OnGetCSV');
+
+ if ( in_array($event->Name, $csv_events) ) {
+ $csv_helper =& $this->Application->recallObject('CSVHelper');
+ /* @var $csv_helper kCSVHelper */
+
+ $prefix = $csv_helper->getPrefix(stripos($event->Name, 'import') !== false);
+
+ $perm_mapping = Array (
+ 'OnCSVImportBegin' => 'OnProcessSelected',
+ 'OnCSVImportStep' => 'OnProcessSelected',
+ 'OnExportCSV' => 'OnLoad',
+ 'OnGetCSV' => 'OnLoad',
+ );
+
+ $tmp_event = new kEvent($prefix . ':' . $perm_mapping[$event->Name] );
+ $perm_value = $perm_helper->CheckEventPermission($tmp_event, $this->permMapping);
+ }
+
+ if ( isset($perm_value) ) {
return $perm_helper->finalizePermissionCheck($event, $perm_value);
}
return parent::CheckPermission($event);
}
/**
- * Enter description here...
+ * Reset mod-rewrite url cache
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnResetModRwCache(&$event)
+ protected function OnResetModRwCache(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') == 'yes') {
+ if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
}
@@ -110,7 +126,7 @@
* @return void
* @access protected
*/
- protected function OnResetSections(&$event)
+ protected function OnResetSections(kEvent &$event)
{
if ($this->Application->GetVar('ajax') == 'yes') {
$event->status = kEvent::erSTOP;
@@ -127,13 +143,20 @@
$event->SetRedirectParam('action_completed', 1);
}
- function OnResetConfigsCache(&$event)
+ /**
+ * Resets unit config cache
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnResetConfigsCache(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') == 'yes') {
+ if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
}
- if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
$this->Application->rebuildCache('master:config_files', kCache::REBUILD_LATER, CacheSettings::$unitCacheRebuildTime);
}
else {
@@ -152,10 +175,12 @@
* Resets parsed data from unit configs
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnResetParsedData(&$event)
+ protected function OnResetParsedData(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') == 'yes') {
+ if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
}
@@ -185,7 +210,14 @@
$event->SetRedirectParam('action_completed', 1);
}
- function OnCompileTemplates(&$event)
+ /**
+ * Compiles all templates (with a progress bar)
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnCompileTemplates(kEvent &$event)
{
$compiler =& $this->Application->recallObject('NParserCompiler');
/* @var $compiler NParserCompiler */
@@ -198,8 +230,10 @@
* Deletes all compiled templates
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnDeleteCompiledTemplates(&$event)
+ protected function OnDeleteCompiledTemplates(kEvent &$event)
{
if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
@@ -220,7 +254,15 @@
$event->SetRedirectParam('action_completed', 1);
}
- function _deleteCompiledTemplates($folder, $unlink_folder = false)
+ /**
+ * Deletes compiled templates in a given folder
+ *
+ * @param string $folder
+ * @param bool $unlink_folder
+ * @return void
+ * @access protected
+ */
+ protected function _deleteCompiledTemplates($folder, $unlink_folder = false)
{
$sub_folders = glob($folder . '/*', GLOB_ONLYDIR);
@@ -244,34 +286,35 @@
}
/**
- * Generates sturcture for specified table
+ * Generates structure for specified table
*
* @param kEvent $event
- * @author Alex
+ * @return void
+ * @access protected
*/
- function OnGenerateTableStructure(&$event)
+ protected function OnGenerateTableStructure(kEvent &$event)
{
- $types_hash = Array(
+ $types_hash = Array (
'string' => 'varchar|text|mediumtext|longtext|date|datetime|time|timestamp|char|year|enum|set',
'int' => 'smallint|mediumint|int|bigint|tinyint',
'float' => 'float|double|decimal',
);
$table_name = $this->Application->GetVar('table_name');
- if (!$table_name) {
+ if ( !$table_name ) {
echo 'error: no table name specified';
- return ;
+ return;
}
- if (TABLE_PREFIX && !preg_match('/^'.preg_quote(TABLE_PREFIX, '/').'(.*)/', $table_name) && (strtolower($table_name) != $table_name)) {
+ if ( TABLE_PREFIX && !preg_match('/^' . preg_quote(TABLE_PREFIX, '/') . '(.*)/', $table_name) && (strtolower($table_name) != $table_name) ) {
// table name without prefix, then add it (don't affect K3 tables named in lowercase)
- $table_name = TABLE_PREFIX.$table_name;
+ $table_name = TABLE_PREFIX . $table_name;
}
- if (!$this->Conn->TableFound($table_name)) {
+ if ( !$this->Conn->TableFound($table_name) ) {
// table with prefix doesn't exist, assume that just config prefix passed -> resolve table name from it
$prefix = preg_replace('/^' . preg_quote(TABLE_PREFIX, '/') . '/', '', $table_name);
- if ($this->Application->prefixRegistred($prefix)) {
+ if ( $this->Application->prefixRegistred($prefix) ) {
// when prefix is found -> use it's table (don't affect K3 tables named in lowecase)
$table_name = $this->Application->getUnitOption($prefix, 'TableName');
}
@@ -290,23 +333,23 @@
$grid_fields = Array();
$id_field = '';
- $fields = Array();
+ $fields = Array ();
$float_types = Array ('float', 'double', 'numeric');
foreach ($table_info as $field_info) {
- if (preg_match('/l[\d]+_.*/', $field_info['Field'])) {
+ if ( preg_match('/l[\d]+_.*/', $field_info['Field']) ) {
// don't put multilingual fields in config
continue;
}
$field_options = Array ();
- $grid_col_options = Array(
+ $grid_col_options = Array (
'title' => 'la_col_' . $field_info['Field'],
'filter_block' => 'grid_like_filter',
);
// 1. get php field type by mysql field type
foreach ($types_hash as $php_type => $db_types) {
- if (preg_match('/'.$db_types.'/', $field_info['Type'])) {
+ if ( preg_match('/' . $db_types . '/', $field_info['Type']) ) {
$field_options['type'] = $php_type;
break;
}
@@ -316,7 +359,7 @@
$default_value = $field_info['Default'];
$not_null = $field_info['Null'] != 'YES';
- if (is_numeric($default_value)) {
+ if ( is_numeric($default_value) ) {
$default_value = preg_match('/[\.,]/', $default_value) ? (float)$default_value : (int)$default_value;
}
@@ -326,62 +369,61 @@
if ( in_array($php_type, $float_types) ) {
// this is float number
- if (preg_match('/'.$db_types.'\([\d]+,([\d]+)\)/i', $field_info['Type'], $regs)) {
+ if ( preg_match('/' . $db_types . '\([\d]+,([\d]+)\)/i', $field_info['Type'], $regs) ) {
// size is described in structure -> add formatter
$field_options['formatter'] = 'kFormatter';
- $field_options['format'] = '%01.'.$regs[1].'f';
+ $field_options['format'] = '%01.' . $regs[1] . 'f';
- if ($not_null) {
+ if ( $not_null ) {
// null fields, will most likely have NULL as default value
$default_value = 0;
}
}
- elseif ($not_null) {
+ elseif ( $not_null ) {
// no size information, just convert to float
// null fields, will most likely have NULL as default value
$default_value = (float)$default_value;
-
}
}
- if (preg_match('/varchar\(([\d]+)\)/i', $field_info['Type'], $regs)) {
+ if ( preg_match('/varchar\(([\d]+)\)/i', $field_info['Type'], $regs) ) {
$field_options['max_len'] = (int)$regs[1];
}
- if (preg_match('/tinyint\([\d]+\)/i', $field_info['Type'])) {
+ if ( preg_match('/tinyint\([\d]+\)/i', $field_info['Type']) ) {
$field_options['formatter'] = 'kOptionsFormatter';
$field_options['options'] = Array (1 => 'la_Yes', 0 => 'la_No');
$field_options['use_phrases'] = 1;
$grid_col_options['filter_block'] = 'grid_options_filter';
}
- if ($not_null) {
+ if ( $not_null ) {
$field_options['not_null'] = 1;
}
- if ($field_info['Key'] == 'PRI') {
+ if ( $field_info['Key'] == 'PRI' ) {
$default_value = 0;
$id_field = $field_info['Field'];
}
- if ($php_type == 'int' && !$not_null) {
+ if ( $php_type == 'int' && !$not_null ) {
// numeric null field
- if (preg_match('/(On|Date)$/', $field_info['Field']) || $field_info['Field'] == 'Modified') {
+ if ( preg_match('/(On|Date)$/', $field_info['Field']) || $field_info['Field'] == 'Modified' ) {
$field_options['formatter'] = 'kDateFormatter';
$grid_col_options['filter_block'] = 'grid_date_rage_filter';
}
}
- if ($php_type == 'int' && ($not_null || is_numeric($default_value))) {
+ if ( $php_type == 'int' && ($not_null || is_numeric($default_value)) ) {
// is integer field AND not null
$field_options['default'] = (int)$default_value;
}
else {
$field_options['default'] = $default_value;
}
- $fields[ $field_info['Field'] ] = $field_options;
- $grids_fields[ $field_info['Field'] ] = $grid_col_options;
+ $fields[$field_info['Field']] = $field_options;
+ $grids_fields[$field_info['Field']] = $grid_col_options;
}
$grids['Default']['Fields'] = $grids_fields;
@@ -416,10 +458,12 @@
* Refreshes ThemeFiles & Theme tables by actual content on HDD
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnRebuildThemes(&$event)
+ protected function OnRebuildThemes(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') == 'yes') {
+ if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
}
@@ -431,7 +475,14 @@
$event->SetRedirectParam('action_completed', 1);
}
- function OnSaveColumns(&$event)
+ /**
+ * Saves grid column widths after their resize by user
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnSaveColumns(kEvent &$event)
{
$picker_helper =& $this->Application->recallObject('ColumnPickerHelper');
/* @var $picker_helper kColumnPickerHelper */
@@ -451,11 +502,13 @@
* Saves various admin settings via ajax
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnSaveSetting(&$event)
+ protected function OnSaveSetting(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') != 'yes') {
- return ;
+ if ( $this->Application->GetVar('ajax') != 'yes' ) {
+ return;
}
$var_name = $this->Application->GetVar('var_name');
@@ -470,8 +523,10 @@
* Just closes popup & deletes last_template & opener_stack if popup, that is closing
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnClosePopup(&$event)
+ protected function OnClosePopup(kEvent &$event)
{
$event->SetRedirectParam('opener', 'u');
}
@@ -480,11 +535,13 @@
* Occurs right after initialization of the kernel, used mainly as hook-to event
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnStartup(&$event)
+ protected function OnStartup(kEvent &$event)
{
if ( $this->Application->isAdmin ) {
- return ;
+ return;
}
$base_url = preg_quote($this->Application->BaseURL(), '/');
@@ -500,17 +557,22 @@
* Occurs right before echoing the output, in Done method of application, used mainly as hook-to event
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBeforeShutdown(&$event)
+ protected function OnBeforeShutdown(kEvent &$event)
{
+
}
/**
* Is called after tree was build (when not from cache)
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnAfterBuildTree(&$event)
+ protected function OnAfterBuildTree(kEvent &$event)
{
}
@@ -519,114 +581,85 @@
* Called by AJAX to perform CSV export
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnExportCSV(&$event)
+ protected function OnExportCSV(kEvent &$event)
{
- $export_helper =& $this->Application->recallObject('CSVHelper');
- /* @var $export_helper kCSVHelper */
+ $csv_helper =& $this->Application->recallObject('CSVHelper');
+ /* @var $csv_helper kCSVHelper */
- $prefix_special = $this->Application->GetVar('PrefixSpecial');
- if(!$prefix_special) {
- $prefix_special = $export_helper->ExportData('prefix');
- }
- $prefix_elems = preg_split('/\.|_/', $prefix_special, 2);
- $perm_sections = $this->Application->getUnitOption($prefix_elems[0], 'PermSection');
-
- if(!$this->Application->CheckPermission($perm_sections['main'].'.view')) {
- $event->status = kEvent::erPERM_FAIL;
- return ;
- }
-
- $export_helper->PrefixSpecial = $prefix_special;
- $export_helper->grid = $this->Application->GetVar('grid');
- $export_helper->ExportStep();
+ $csv_helper->PrefixSpecial = $csv_helper->getPrefix(false);
+ $csv_helper->grid = $this->Application->GetVar('grid');
+ $csv_helper->ExportStep();
$event->status = kEvent::erSTOP;
}
/**
* Returning created by AJAX CSV file
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnGetCSV(&$event)
+ protected function OnGetCSV(kEvent &$event)
{
- $export_helper =& $this->Application->recallObject('CSVHelper');
- /* @var $export_helper kCSVHelper */
+ $csv_helper =& $this->Application->recallObject('CSVHelper');
+ /* @var $csv_helper kCSVHelper */
- $prefix_special = $export_helper->ExportData('prefix');
- $prefix_elems = preg_split('/\.|_/', $prefix_special, 2);
- $perm_sections = $this->Application->getUnitOption($prefix_elems[0], 'PermSection');
-
- if(!$this->Application->CheckPermission($perm_sections['main'].'.view')) {
- $event->status = kEvent::erPERM_FAIL;
- return ;
- }
-
- $export_helper->GetCSV();
+ $csv_helper->GetCSV();
}
/**
- * Enter description here...
+ * Start CSV import
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnCSVImportBegin(&$event)
+ protected function OnCSVImportBegin(kEvent &$event)
{
- $prefix_special = $this->Application->GetVar('PrefixSpecial');
- $prefix_elems = preg_split('/\.|_/', $prefix_special, 2);
- $perm_sections = $this->Application->getUnitOption($prefix_elems[0], 'PermSection');
-
- if(!$this->Application->CheckPermission($perm_sections['main'].'.add') && !$this->Application->CheckPermission($perm_sections['main'].'.edit')) {
- $event->status = kEvent::erPERM_FAIL;
- return ;
- }
-
- $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object =& $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- $field_values = array_shift($items_info);
- $object->SetFieldsFromHash($field_values);
+ $object->SetFieldsFromHash( $this->getSubmittedFields($event) );
+
$event->redirect = false;
$result = 'required';
- if($object->GetDBField('ImportFile')) {
- $import_helper =& $this->Application->recallObject('CSVHelper');
- /* @var $import_helper kCSVHelper */
- $import_helper->PrefixSpecial = $this->Application->GetVar('PrefixSpecial');
- $import_helper->grid = $this->Application->GetVar('grid');
- $result = $import_helper->ImportStart( $object->GetField('ImportFile', 'file_paths') );
- if($result === true) {
+
+ if ( $object->GetDBField('ImportFile') ) {
+ $csv_helper =& $this->Application->recallObject('CSVHelper');
+ /* @var $csv_helper kCSVHelper */
+
+ $csv_helper->PrefixSpecial = $csv_helper->getPrefix(true);
+ $csv_helper->grid = $this->Application->GetVar('grid');
+ $result = $csv_helper->ImportStart($object->GetField('ImportFile', 'file_paths'));
+
+ if ( $result === true ) {
$event->redirect = $this->Application->GetVar('next_template');
$event->SetRedirectParam('PrefixSpecial', $this->Application->GetVar('PrefixSpecial'));
$event->SetRedirectParam('grid', $this->Application->GetVar('grid'));
}
}
- if($event->redirect === false) {
+ if ( $event->redirect === false ) {
$object->SetError('ImportFile', $result);
$event->status = kEvent::erFAIL;
}
}
/**
- * Enter description here...
+ * Performs one CSV import step
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnCSVImportStep(&$event)
+ protected function OnCSVImportStep(kEvent &$event)
{
$import_helper =& $this->Application->recallObject('CSVHelper');
/* @var $import_helper kCSVHelper */
- $prefix_special = $import_helper->ImportData('prefix');
- $prefix_elems = preg_split('/\.|_/', $prefix_special, 2);
- $perm_sections = $this->Application->getUnitOption($prefix_elems[0], 'PermSection');
-
- if ( !$this->Application->CheckPermission($perm_sections['main'] . '.add') && !$this->Application->CheckPermission($perm_sections['main'] . '.edit') ) {
- $event->status = kEvent::erPERM_FAIL;
- return;
- }
-
$import_helper->ImportStep();
$event->status = kEvent::erSTOP;
}
@@ -635,8 +668,10 @@
* Shows unit config filename, where requested prefix is defined
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnCheckPrefixConfig(&$event)
+ protected function OnCheckPrefixConfig(kEvent &$event)
{
$prefix = $this->Application->GetVar('config_prefix');
$config_file = $this->Application->UnitConfigReader->prefixFiles[$prefix];
@@ -656,37 +691,45 @@
Close Window
Application->ParseBlock(Array('name' => 'incs/footer'));
+ echo $this->Application->ParseBlock(Array ('name' => 'incs/footer'));
echo ob_get_clean();
$event->status = kEvent::erSTOP;
}
- function OnDropTempTablesByWID(&$event)
+ /**
+ * Deletes temp tables, when user closes window using "x" button in top right corner
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnDropTempTablesByWID(kEvent &$event)
{
$sid = $this->Application->GetSID();
$wid = $this->Application->GetVar('m_wid');
$tables = $this->Conn->GetCol('SHOW TABLES');
- $mask_edit_table = '/'.TABLE_PREFIX.'ses_'.$sid.'_'.$wid.'_edit_(.*)$/';
- foreach($tables as $table)
- {
- if( preg_match($mask_edit_table,$table,$rets) )
- {
- $this->Conn->Query('DROP TABLE IF EXISTS '.$table);
+ $mask_edit_table = '/' . TABLE_PREFIX . 'ses_' . $sid . '_' . $wid . '_edit_(.*)$/';
+
+ foreach ($tables as $table) {
+ if ( preg_match($mask_edit_table, $table, $rets) ) {
+ $this->Conn->Query('DROP TABLE IF EXISTS ' . $table);
}
}
+
echo 'OK';
$event->status = kEvent::erSTOP;
- return ;
}
/**
* Backup all data
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBackup(&$event)
+ protected function OnBackup(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -702,8 +745,10 @@
* Perform next backup step
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBackupProgress(&$event)
+ protected function OnBackupProgress(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -723,8 +768,10 @@
* Stops Backup & redirect to Backup template
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBackupCancel(&$event)
+ protected function OnBackupCancel(kEvent &$event)
{
$event->redirect = 'tools/backup1';
}
@@ -733,8 +780,10 @@
* Starts restore process
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnRestore(&$event)
+ protected function OnRestore(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -743,7 +792,14 @@
$event->redirect = 'tools/restore3';
}
- function OnRestoreProgress(&$event)
+ /**
+ * Performs next restore step
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnRestoreProgress(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -772,8 +828,10 @@
* Stops Restore & redirect to Restore template
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnRestoreCancel(&$event)
+ protected function OnRestoreCancel(kEvent &$event)
{
$event->redirect = 'tools/restore1';
}
@@ -782,8 +840,10 @@
* Deletes one backup file
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnDeleteBackup(&$event)
+ protected function OnDeleteBackup(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -795,37 +855,33 @@
* Starts restore process
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnSqlQuery(&$event)
+ protected function OnSqlQuery(kEvent &$event)
{
$sql = $this->Application->GetVar('sql');
- if ($sql) {
+
+ if ( $sql ) {
$start = microtime(true);
$result = $this->Conn->Query($sql);
$this->Application->SetVar('sql_time', round(microtime(true) - $start, 7));
-
- if ($result)
- {
- if (is_array($result))
- {
+ if ( $result ) {
+ if ( is_array($result) ) {
$this->Application->SetVar('sql_has_rows', 1);
$this->Application->SetVar('sql_rows', serialize($result));
}
}
$check_sql = trim(strtolower($sql));
- if (
- (substr($check_sql, 0, 6) == 'insert')
- || (substr($check_sql, 0, 6) == 'update')
- || (substr($check_sql, 0, 7) == 'replace')
- || (substr($check_sql, 0, 6) == 'delete')
- ) {
+
+ if ( preg_match('/^(insert|update|replace|delete)/', $check_sql) ) {
$this->Application->SetVar('sql_has_affected', 1);
$this->Application->SetVar('sql_affected', $this->Conn->getAffectedRows());
}
-
}
+
$this->Application->SetVar('query_status', 1);
$event->status = kEvent::erFAIL;
}
@@ -834,8 +890,10 @@
* Occurs after unit config cache was successfully rebuilt
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnAfterCacheRebuild(&$event)
+ protected function OnAfterCacheRebuild(kEvent &$event)
{
}
@@ -868,13 +926,15 @@
* Saves menu (tree) frame width
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnSaveMenuFrameWidth(&$event)
+ protected function OnSaveMenuFrameWidth(kEvent &$event)
{
$event->status = kEvent::erSTOP;
- if (!$this->Application->ConfigValue('ResizableFrames')) {
- return ;
+ if ( !$this->Application->ConfigValue('ResizableFrames') ) {
+ return;
}
$this->Application->SetConfigValue('MenuFrameWidth', (int)$this->Application->GetVar('width'));
@@ -884,34 +944,36 @@
* Retrieves data from memory cache
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnMemoryCacheGet(&$event)
+ protected function OnMemoryCacheGet(kEvent &$event)
{
$event->status = kEvent::erSTOP;
$ret = Array ('message' => '', 'code' => 0); // 0 - ok, > 0 - error
$key = $this->Application->GetVar('key');
- if (!$key) {
+ if ( !$key ) {
$ret['code'] = 1;
$ret['message'] = 'Key name missing';
}
else {
$value = $this->Application->getCache($key);
$ret['value'] =& $value;
- $ret['size'] = is_string($value) ? kUtil::formatSize( strlen($value) ) : '?';
+ $ret['size'] = is_string($value) ? kUtil::formatSize(strlen($value)) : '?';
$ret['type'] = gettype($value);
- if (kUtil::IsSerialized($value)) {
+ if ( kUtil::IsSerialized($value) ) {
$value = unserialize($value);
}
- if (is_array($value)) {
+ if ( is_array($value) ) {
$ret['value'] = print_r($value, true);
}
- if ($ret['value'] === false) {
+ if ( $ret['value'] === false ) {
$ret['code'] = 2;
$ret['message'] = 'Key "' . $key . '" doesn\'t exist';
}
@@ -927,15 +989,17 @@
* Retrieves data from memory cache
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnMemoryCacheSet(&$event)
+ protected function OnMemoryCacheSet(kEvent &$event)
{
$event->status = kEvent::erSTOP;
$ret = Array ('message' => '', 'code' => 0); // 0 - ok, > 0 - error
$key = $this->Application->GetVar('key');
- if (!$key) {
+ if ( !$key ) {
$ret['code'] = 1;
$ret['message'] = 'Key name missing';
}
@@ -958,8 +1022,10 @@
* Usage: "php tools/run_event.php adm:OnDeploy b674006f3edb1d9cd4d838c150b0567d"
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnDeploy(&$event)
+ protected function OnDeploy(kEvent &$event)
{
if ( isset($GLOBALS['argv']) ) {
// command line invocation -> don't perform redirect
@@ -978,8 +1044,10 @@
* Synchronizes database revisions from "project_upgrades.sql" file
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnSynchronizeDBRevisions(&$event)
+ protected function OnSynchronizeDBRevisions(kEvent &$event)
{
$deployment_helper =& $this->Application->recallObject('DeploymentHelper');
/* @var $deployment_helper DeploymentHelper */
@@ -1001,7 +1069,7 @@
* @return void
* @access protected
*/
- protected function OnOptimizePerformance(&$event)
+ protected function OnOptimizePerformance(kEvent &$event)
{
$start_time = adodb_mktime();
@@ -1021,7 +1089,7 @@
$sid = $matches[1];
- if ( isset($active_sessions[$sid]) || (filemtime($file_path . $file_name) > $start_time ) ) {
+ if ( isset($active_sessions[$sid]) || (filemtime($file_path . $file_name) > $start_time) ) {
// debug file belongs to an active session
// debug file is recently created (after sessions snapshot)
continue;
@@ -1043,17 +1111,24 @@
var $parentPath = Array ();
- function decorate($var, $level = 0)
+ /**
+ * Decorates given array
+ *
+ * @param Array $var
+ * @param int $level
+ * @return string
+ */
+ public function decorate($var, $level = 0)
{
$ret = '';
$deep_level = count($this->parentPath);
- if ($deep_level && ($this->parentPath[0] == 'Fields')) {
+ if ( $deep_level && ($this->parentPath[0] == 'Fields') ) {
$expand = $level < 2;
}
- elseif ($deep_level && ($this->parentPath[0] == 'Grids')) {
- if ($deep_level == 3 && $this->parentPath[2] == 'Icons') {
+ elseif ( $deep_level && ($this->parentPath[0] == 'Grids') ) {
+ if ( $deep_level == 3 && $this->parentPath[2] == 'Icons' ) {
$expand = false;
}
else {
@@ -1064,7 +1139,7 @@
$expand = $level == 0;
}
- if (is_array($var)) {
+ if ( is_array($var) ) {
$ret .= 'Array (';
$prepend = $expand ? "\n" . str_repeat("\t", $level + 1) : '';
@@ -1078,10 +1153,10 @@
$ret = rtrim($ret, ', ') . $prepend . ')';
}
else {
- if (is_null($var)) {
+ if ( is_null($var) ) {
$ret = 'NULL';
}
- elseif (is_string($var)) {
+ elseif ( is_string($var) ) {
$ret = "'" . $var . "'";
}
else {
Index: branches/5.2.x/core/install/upgrade_helper.php
===================================================================
diff -u -N -r14244 -r14870
--- branches/5.2.x/core/install/upgrade_helper.php (.../upgrade_helper.php) (revision 14244)
+++ branches/5.2.x/core/install/upgrade_helper.php (.../upgrade_helper.php) (revision 14870)
@@ -1,6 +1,6 @@
_toolkit =& $instance;
}
+ /**
+ * Replaces deprecated detail template design with new one
+ *
+ * @param string $prefix
+ * @param string $from_template
+ * @param string $to_template
+ */
+ function _updateDetailTemplate($prefix, $from_template, $to_template)
+ {
+ $sql = 'SELECT CustomFieldId
+ FROM ' . TABLE_PREFIX . 'CustomField
+ WHERE FieldName = "' . $prefix . '_ItemTemplate"';
+ $custom_field_id = $this->Conn->GetOne($sql);
+
+ $ml_formatter =& $this->Application->recallObject('kMultiLanguage');
+ /* @var $ml_formatter kMultiLanguage */
+
+ $field = $ml_formatter->LangFieldName('cust_' . $custom_field_id, true);
+
+ $sql = 'UPDATE ' . TABLE_PREFIX . 'CategoryCustomData
+ SET ' . $field . ' = "' . $to_template . '"
+ WHERE ' . $field . ' = "' . $from_template . '"';
+ $this->Conn->Query($sql);
+ }
}