Пример #1
0
 public static function onCCK_Storage_LocationImport($data, &$config = array(), $pk = 0)
 {
     if (!$config['pk']) {
         // Init
         if (!$pk) {
             if (isset($config['key']) && $config['key']) {
                 if (isset($data[$config['key']]) && $data[$config['key']] != '') {
                     $pk = JCckDatabase::loadResult('SELECT ' . self::$key . ' FROM ' . self::$table . ' WHERE ' . $config['key'] . ' = "' . $data[$config['key']] . '"');
                 }
                 $pk = $pk > 0 ? $pk : 0;
             } else {
                 $pk = isset($data[self::$key]) && $data[self::$key] > 0 ? $data[self::$key] : 0;
             }
         }
         $table = self::_getTable($pk);
         $isNew = $table->{self::$key} > 0 ? false : true;
         $iPk = 0;
         if ($isNew) {
             if (isset($data[self::$key])) {
                 $iPk = $data[self::$key];
                 unset($data[self::$key]);
             }
             $config['log'] = 'created';
         } else {
             preg_match('#::cck::(.*)::/cck::#U', $table->{self::$custom}, $matches);
             $config['id'] = $matches[1];
             $config['log'] = 'updated';
         }
         if (!$config['id']) {
             $config['id'] = parent::g_onCCK_Storage_LocationPrepareStore();
         }
         self::_initTable($table, $data, $config, true);
         // Prepare
         $table->bind($data);
         if ($isNew && !isset($data['rules'])) {
             $data['rules'] = array('core.delete' => array(), 'core.edit' => array(), 'core.edit.state' => array());
             $rules = new JAccessRules($data['rules']);
             $table->setRules($rules);
         }
         if (!@$table->title) {
             $table->title = JFactory::getDate()->format('Y-m-d-H-i-s');
             $table->check();
             $table->alias .= '-' . $config['x'];
         } else {
             $table->check();
         }
         self::_completeTable($table, $data, $config);
         // Store
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('content');
         $dispatcher->trigger('onContentBeforeSave', array(self::$context, &$table, $isNew));
         if (!$table->store()) {
             $config['error'] = true;
             $config['log'] = 'cancelled';
             $config['pk'] = $pk;
             parent::g_onCCK_Storage_LocationRollback($config['id']);
             return false;
         }
         $dispatcher->trigger('onContentAfterSave', array(self::$context, &$table, $isNew));
         // Featured
         self::_setFeatured($table, $isNew);
         // Tweak
         if ($iPk > 0) {
             if (JCckDatabase::execute('UPDATE ' . self::$table . ' SET ' . self::$key . ' = ' . (int) $iPk . ' WHERE ' . self::$key . ' = ' . (int) $table->{self::$key})) {
                 $table->{self::$key} = $iPk;
                 $config['auto_inc'] = $iPk > $config['auto_inc'] ? $iPk : $config['auto_inc'];
                 if ($table->asset_id) {
                     JCckDatabase::execute('UPDATE #__assets SET name = "com_content.article.' . $iPk . '" WHERE id = ' . (int) $table->asset_id);
                 }
             }
         }
         if (!$config['pk']) {
             $config['pk'] = $table->{self::$key};
         }
         $config['author'] = $table->{self::$author};
         $config['parent'] = $table->{self::$parent};
     }
     parent::g_onCCK_Storage_LocationStore($data, self::$table, $config['pk'], $config);
     return true;
 }