Ejemplo n.º 1
0
 protected function setup()
 {
     $md5_psfiles = $this->getXmlMd5File('prestashop/' . _PS_VERSION_ . '.xml', 'ps_root_dir', _PS_VERSION_);
     list(, , , , $pp_files, ) = $vars1 = $this->getSetupVars1();
     $this->setupOverriddenFiles($vars1);
     foreach ($pp_files as $pp_file) {
         list($setup_rel_path, $setup_amended_rel_path, $rel_path, $file, , ) = $this->getSetupVars2($vars1, $pp_file);
         if ($this->install_mode) {
             $compatibility = $this->checkVersionCompatibility($file, $rel_path, $pp_file);
             if ($compatibility[self::VERSION_CHECK_INDEX] == false) {
                 if (is_array($md5_psfiles)) {
                     $ps_files = array_keys($md5_psfiles);
                 }
                 $do_copy = !file_exists($file);
                 if (!$do_copy) {
                     if (is_array($ps_files) && in_array($setup_amended_rel_path, $ps_files)) {
                         $do_copy = PSM::md5Compare($file, $md5_psfiles[$setup_amended_rel_path]);
                     }
                 }
                 if ($do_copy) {
                     $this->backupFile($file);
                     if (!is_dir(dirname($file))) {
                         mkdir(dirname($file), 0755, true);
                     }
                     @chmod($file, 0755);
                     Tools::deleteFile($file);
                     Tools::copy($pp_file, $file);
                 }
             }
         } else {
             $restore = PSM::md5filesCompare($pp_file, $file);
             if ($restore) {
                 $this->restoreFile($file);
                 $delete = PSM::md5filesCompare($pp_file, $file);
                 if ($delete) {
                     if (is_array($md5_psfiles)) {
                         $ps_files = array_keys($md5_psfiles);
                     }
                     if (is_array($ps_files) && !in_array($setup_rel_path, $ps_files)) {
                         Tools::deleteFile($file);
                     }
                 }
             }
         }
     }
     if ($this->install_mode) {
         // backward compatibility
         foreach (array('css', 'js') as $type) {
             $bw_file = _PS_THEME_DIR_ . $type . '/modules/' . $this->module->name . '/' . $type . '/pp_theme_custom.' . $type;
             if (is_file($bw_file)) {
                 $dir = _PS_THEME_DIR_ . $type . '/modules/' . $this->module->name;
                 $file = $dir . '/custom.' . $type;
                 if (!is_file($file)) {
                     mkdir($dir, 0755, true);
                     Tools::copy($bw_file, $file);
                 }
                 if (is_file($file)) {
                     Tools::deleteFile($bw_file);
                 }
             }
         }
     }
     if ($this->install_mode) {
         $result = $this->updateDB();
         if ($result) {
             $this->insertData(false);
         }
     }
     $this->setupSmarty($this->install_mode);
     $this->getPPSetupEx()->setup();
     $this->setupPlugins();
     $this->setupExtraModules();
     if (!$this->install_mode) {
         $this->cleanup();
     }
     PSM::clearCache();
     if ($this->install_mode) {
         PSM::protectDirectory(_PS_ROOT_DIR_, array(_PS_MODULE_DIR_));
         PSM::protectDirectory(_PS_MODULE_DIR_ . 'pproperties');
         PSM::protectDirectory(self::getBackupRootDirectory());
     }
 }
Ejemplo n.º 2
0
 /** Called in Back Office when user clicks "Configure" */
 public function getContent()
 {
     if (Configuration::get('PS_DISABLE_NON_NATIVE_MODULE')) {
         return '<div class="module_error alert alert-danger">' . $this->l('Non PrestaShop modules disabled.') . '</div>';
     }
     $this->active_languages = $this->context->controller->getLanguages();
     $this->default_language_id = $this->context->controller->default_form_language;
     $setup = $this->setupInstance();
     if (!(int) Tools::getValue('pp')) {
         $setup->checkIntegration();
     }
     $tab = '0';
     $output0 = $output1 = $output2 = $output3 = $output4 = '';
     $templates = null;
     $properties = null;
     if (Tools::isSubmit('submitRestoreDefaults')) {
         $tab = '0';
         $setup->insertData(true);
     } elseif (Tools::isSubmit('cancelSaveTemplate')) {
         $tab = '0';
     } elseif (Tools::isSubmit('cancelSaveProperty')) {
         $tab = '1';
     } elseif (Tools::isSubmit('submitSaveTemplate')) {
         $result = $this->saveTemplate();
         if ($result['error'] == '') {
             $tab = '0';
         } else {
             $templates = $result['templates'];
             $output4 = $this->displayError($result['error']);
             $tab = '4';
         }
     } elseif (Tools::isSubmit('submitSaveProperty')) {
         $result = $this->saveProperty();
         if ($result['error'] == '') {
             $tab = '1';
         } else {
             $properties = $result['properties'];
             $output4 = $this->displayError($result['error']);
             $tab = '4';
         }
     } elseif (Tools::isSubmit('submitConfigSettings')) {
         $tab = '2';
         Configuration::updateValue('PP_MEASUREMENT_SYSTEM', (int) Tools::getValue('measurement_system', 1));
         Configuration::updateValue('PP_MEASUREMENT_SYSTEM_FO', (int) Tools::getValue('measurement_system_fo', 0));
         Configuration::updateValue('PP_POWEREDBY', (int) Tools::getValue('poweredby', 0));
         Configuration::updateValue('PP_TEMPLATE_NAME_IN_CATALOG', (int) Tools::getValue('template_name_in_catalog', 1));
         Configuration::updateValue('PP_SHOW_POSITIONS', (int) Tools::getValue('show_positions', 0));
         $output2 = $this->displayConfirmation($this->l('Settings updated'));
     } elseif (Tools::isSubmit('submitSetup')) {
         $tab = '2';
         $setup->runSetup();
     } elseif (Tools::isSubmit('submitIntegration')) {
         $tab = '2';
         $setup->runIntegrationTest();
     } elseif (Tools::isSubmit('clickClearCache')) {
         $tab = '2';
         PSM::clearCache();
     } elseif (Tools::isSubmit('submitStatistics')) {
         $tab = '3';
     } elseif (Tools::isSubmit('clickEditTemplate')) {
         $tab = '4';
     } elseif (Tools::isSubmit('clickDeleteTemplate')) {
         $tab = '0';
         $this->deleteTemplate();
     } elseif (Tools::isSubmit('clickHiddenStatusTemplate')) {
         $tab = '0';
         $this->changeHiddenStatus();
     } elseif (Tools::isSubmit('clickEditProperty')) {
         $tab = '4';
     } elseif (Tools::isSubmit('clickDeleteProperty')) {
         $tab = '1';
         $this->deleteProperty();
     }
     $html = '';
     if (version_compare(_PS_VERSION_, $this->ps_versions_compliancy['min']) < 0 || version_compare(_PS_VERSION_, $this->ps_versions_compliancy['max']) > 0) {
         $html .= $this->displayError($this->l('This module is not fully compatible with the installed PrestaShop version.') . ' ' . $this->compatibilityText() . '<br>' . $this->l('Please upgrade to the newer version.') . '<br>');
     }
     if (count($this->integration_test_result) != 0) {
         $html .= $this->displayError($this->l('Integration test failed.'));
         $tab = '2';
     }
     $tabs = array();
     $tabs[0] = array('type' => 'templates', 'name' => $this->l('Templates'), 'html' => $output0 . $this->getTemplatesTabHtml());
     $tabs[1] = array('type' => 'properties', 'name' => $this->l('Properties'), 'html' => $output1 . $this->getPropertiesTabHtml());
     $tabs[2] = array('type' => 'settings', 'name' => $this->l('Settings'), 'html' => $output2 . $this->getSettingsTabHtml(Tools::isSubmit('submitIntegration') || Tools::isSubmit('submitSetup')));
     $tabs[3] = array('type' => 'statistics', 'name' => $this->l('Statistics'), 'html' => $output3 . $this->getStatisticsTabHtml(Tools::isSubmit('submitStatistics')));
     if ($tab == 4 && (Tools::isSubmit('clickEditTemplate') || Tools::isSubmit('submitSaveTemplate'))) {
         $mode = Tools::getValue('mode');
         if ($mode == 'add') {
             $title = $this->l('Add template');
         } elseif ($mode == 'copy') {
             $title = $this->l('Add template');
         } else {
             $mode = 'edit';
             $title = $this->l('Edit template');
         }
         $tabs[4] = array('type' => 'modifyTemplate', 'name' => $title, 'html' => $output4 . $this->getEditTemplateTabHtml($templates, $mode, $title));
     } elseif ($tab == 4 && (Tools::isSubmit('clickEditProperty') || Tools::isSubmit('submitSaveProperty'))) {
         $mode = Tools::getValue('mode');
         if ($mode == 'add') {
             $type = (int) Tools::getValue('type');
             if ($type == self::PROPERTY_TYPE_GENERAL) {
                 $title = $this->l('Add property attribute');
             } elseif ($type == self::PROPERTY_TYPE_BUY_BLOCK_TEXT) {
                 $title = $this->l('Add property text');
             } else {
                 $title = $this->l('Add property dimension');
             }
         } else {
             $mode = 'edit';
             $title = $this->l('Edit property');
         }
         $tabs[4] = array('type' => 'modifyProperty', 'name' => $title, 'html' => $output4 . $this->getEditPropertyTabHtml($properties, $mode, $title));
     }
     //$helper->fields_value['tab'] = $tab;
     $helper = $this->createTemplate('pproperties');
     $helper->tpl_vars['html'] = $html;
     $helper->tpl_vars['tabs'] = $tabs;
     $helper->tpl_vars['active'] = $tab;
     $helper->tpl_vars['version'] = $this->version;
     $helper->tpl_vars['ppe_id'] = PSM::getPSMId($this);
     $helper->tpl_vars['_path'] = $this->getPathUri();
     $helper->tpl_vars['s_user_guide'] = $this->l('user guide');
     $helper->tpl_vars['s_version'] = $this->l('Version');
     $helper->tpl_vars['s_pp_info_ignore'] = $this->l("don't show this message again");
     $helper->tpl_vars['token_adminpproperties'] = Tools::getAdminTokenLite('AdminPproperties');
     $helper->tpl_vars['jstranslations'] = PP::safeOutputJS(array('rerun' => $this->l('Re-run Setup'), 'integration_module_success_IntegrationModuleIgnore' => $this->l('ignored - please re-run setup'), 'integration_module_success_IntegrationModuleIntegrate' => $this->l('integation activated - please re-run setup'), 'integration_module_rerun_IntegrationModuleCheckForUpdates' => $this->l('please re-run setup'), 'integration_module_downloaded_IntegrationModuleCheckForUpdates' => $this->l('update downloaded - please re-run setup'), 'integration_module_no_updates_IntegrationModuleCheckForUpdates' => $this->l('no updates available - please contact customer support'), 'integration_module_error' => $this->l('error occurred')));
     if (!Module::isInstalled('psmextmanager') && Module::getInstanceByName('psmextmanager')) {
         $helper->tpl_vars['psmextmanager_install'] = $this->context->link->getAdminLink('AdminModules') . '&install=psmextmanager&tab_module=administration&module_name=psmextmanager&anchor=Psmextmanager';
     }
     return $helper->generate();
 }