예제 #1
0
파일: data.php 프로젝트: densem-2013/exikom
 /**
  * Do any extra work needed after doing real data restore.
  *
  * @param   array  &$backup  Uploaded backup file.
  *
  * @return  void
  */
 protected function afterRestore(&$backup)
 {
     $session = JFactory::getSession();
     $sessionQueue = $session->get('registry');
     $sessionQueue->set('com_jsnuniform', null);
     $dataForm = $this->getForm();
     $checkTableSubmissions = true;
     foreach ($this->data->tables->table as $table) {
         if ((string) $table['name'] == "#__jsn_uniform_submissions") {
             $checkTableSubmissions = false;
         }
     }
     $checkTableSubmissionData = true;
     foreach ($this->data->tables->table as $table) {
         if ((string) $table['name'] == "#__jsn_uniform_submission_data") {
             $checkTableSubmissionData = false;
         }
     }
     if (!empty($dataForm) && count($dataForm) && $checkTableSubmissionData && $checkTableSubmissionData) {
         foreach ($dataForm as $formId) {
             if (!empty($formId->form_id) && (int) $formId->form_id) {
                 $fieldSubmission = array();
                 $fieldSubmission[] = "`data_id` int(11)";
                 $getFields = $this->getFields($formId->form_id);
                 if (!empty($getFields) && is_array($getFields) && count($getFields)) {
                     foreach ($getFields as $field) {
                         if (!empty($field->field_id) && !empty($field->field_type)) {
                             if ($field->field_type != 'google-maps' && $field->field_type != 'static-heading' && $field->field_type != 'static-paragraph' && $field->field_type != 'horizontal-ruler' && $field->field_type != 'static-content') {
                                 $fieldSubmission[] = '`sb_' . $field->field_id . '` ' . JSNUniformHelper::replaceField($field->field_type);
                             }
                         }
                     }
                     $fieldSubmission = implode(",", $fieldSubmission);
                     $this->_db->setQuery("DROP TABLE IF EXISTS #__jsn_uniform_submissions_{$formId->form_id}");
                     $this->_db->execute();
                     $this->_db->setQuery("CREATE TABLE IF NOT EXISTS #__jsn_uniform_submissions_{$formId->form_id} ({$fieldSubmission})");
                     $this->_db->execute();
                 }
             }
         }
     }
     $folderUpload = $this->getFolderUploadConfig();
     if (!empty($folderUpload)) {
         $folderUrl = $folderUpload->value . '/jsnuniform_uploads/';
         if (JFolder::exists(JPath::clean(JPATH_ROOT . $folderUrl))) {
             /*
             if (!JFile::exists(JPATH_ROOT . $folderUrl . '/.htaccess'))
             {
             	$file = JPath::clean(JPATH_ROOT . $folderUrl . '/.htaccess');
             	$buffer = "RemoveHandler .php .phtml .php3 \nRemoveType .php .phtml .php3 \nphp_flag engine off \n ";
             	JFile::write($file, $buffer, true);
             }
             */
         }
     }
     $this->restoreTables();
     $query = $this->_db->getQuery(true);
     $query->update($this->_db->quoteName("#__jsn_uniform_fields"));
     $query->set("field_type = " . $this->_db->Quote("static-content"));
     $query->where("field_type='static-heading'", "OR");
     $query->where("field_type='static-paragraph'", "OR");
     $query->where("field_type='horizontal-ruler'", "OR");
     $this->_db->setQuery($query);
     $this->_db->execute();
     $this->_db->setQuery($this->_db->getQuery(true)->select('*')->from("#__jsn_uniform_form_pages"));
     if ($data = $this->_db->loadObjectList()) {
         foreach ($data as $item) {
             $newContent = array();
             $newTemplate = new stdClass();
             $templateItem = array();
             if (isset($item->page_content)) {
                 $pageContent = json_decode($item->page_content);
                 if ($pageContent && (is_array($pageContent) || is_object($pageContent))) {
                     foreach ($pageContent as $content) {
                         if ($content->type == 'static-heading') {
                             $content->type = 'static-content';
                             $typeHeading = isset($content->options->type) ? $content->options->type : '';
                             $labelHeading = isset($content->options->label) ? $content->options->label : '';
                             $content->options->value = "<{$typeHeading}>{$labelHeading}</{$typeHeading}>";
                         } else {
                             if ($content->type == 'static-paragraph') {
                                 $content->type = 'static-content';
                             } else {
                                 if ($content->type == 'horizontal-ruler') {
                                     $content->type = 'static-content';
                                     $sizeHr = isset($content->options->size) ? $content->options->size : '';
                                     $content->options->value = "<hr class=\"{$sizeHr}\"/>";
                                 }
                             }
                         }
                         $newContent[] = $content;
                     }
                 }
             }
             $query = $this->_db->getQuery(true);
             $query->update($this->_db->quoteName("#__jsn_uniform_form_pages"));
             $query->set("page_content = " . $this->_db->Quote(json_encode($newContent)));
             $query->where("page_id = " . intval($item->page_id));
             $this->_db->setQuery($query);
             $this->_db->execute();
         }
     }
     if ($checkTableSubmissions) {
         JSNUniformHelper::convertTableSubmissions('restore');
     }
     if ($checkTableSubmissionData) {
         JSNUniformHelper::convertTableSubmissionData('restore');
     }
 }