예제 #1
0
 function _restoreShowcaseTheme()
 {
     require_once JPATH_COMPONENT . DS . 'classes' . DS . 'jsn_is_upgradethemedb.php';
     $objJSNPlugins = JSNISFactory::getObj('classes.jsn_is_plugins');
     $queries = array();
     if (!isset($this->_document->themes)) {
         return $queries;
     }
     $objTmpTheme = new stdClass();
     $objTmpTheme->version = '1.0.0';
     $objTheme = new stdClass();
     $objTheme->folder = 'jsnimageshow';
     $themesRoot = $this->_document->themes;
     $themes = $this->_getShowcaseTheme();
     if (count($themes)) {
         foreach ($themes as $theme) {
             $fieldChanged = array();
             $themeName = JString::str_ireplace('theme', 'theme_', $theme);
             //$checkTableTheme = $this->_checkTableExist('#__imageshow_'.$themeName);
             //if(!$checkTableTheme) continue;
             $objTheme->element = $theme;
             $manifest = $objJSNPlugins->getXmlFile($objTheme, false);
             $objUpgradeThemeDB = new JSNISUpgradeThemeDB($manifest, $objTmpTheme);
             $items = $objUpgradeThemeDB->extractVersionRange();
             $preDataChange = $objUpgradeThemeDB->getFieldChanged($items);
             $dataChange = $objUpgradeThemeDB->processDataChanged($preDataChange);
             if (isset($dataChange['#__imageshow_' . $themeName])) {
                 foreach ($dataChange['#__imageshow_' . $themeName] as $items) {
                     foreach ($items as $key => $item) {
                         $fieldChanged[$key] = $item['change'];
                     }
                 }
             }
             if (isset($themesRoot[0]->{$theme})) {
                 $root = $themesRoot[0]->{$theme};
                 $tables = @$root[0]->tables;
                 $subtables = @$tables[0]->table;
                 if (count($subtables)) {
                     for ($i = 0, $counti = count($subtables); $i < $counti; $i++) {
                         $attributes = array();
                         $tableAttributes = $subtables[$i]->attributes();
                         $tableName = (string) $tableAttributes->name;
                         $records = $subtables[$i]->records;
                         $subrecords = $records[0]->record;
                         $queries[] = 'TRUNCATE ' . $tableName;
                         $queries[] = 'ALTER TABLE ' . $tableName . ' AUTO_INCREMENT = 1';
                         for ($k = 0, $countk = count($subrecords); $k < $countk; $k++) {
                             $rows = $subrecords[$k];
                             $attributes[] = $rows->attributes();
                         }
                         if (count($attributes)) {
                             foreach ($attributes as $attribute) {
                                 $fields = '';
                                 $fieldsValue = '';
                                 foreach ($attribute as $key => $value) {
                                     if (count($fieldChanged) && isset($fieldChanged[$key])) {
                                         $key = $fieldChanged[$key];
                                     }
                                     if ($this->_checkTableColumExist($tableName, $key)) {
                                         $fields .= $key . ',';
                                         $fieldsValue .= $this->_db->quote((string) $value) . ',';
                                     }
                                 }
                                 $queries[] = 'INSERT ' . $tableName . ' (' . substr($fields, 0, -1) . ') VALUES (' . substr($fieldsValue, 0, -1) . ')';
                             }
                         }
                     }
                 }
             }
         }
     }
     return $queries;
 }