Example #1
0
 /**
  * PROCESS : installFixtures
  * Install fixtures (E.g. demo products)
  */
 public function installFixtures($entity = null, array $data = array())
 {
     $fixtures_path = _PS_INSTALL_FIXTURES_PATH_ . 'apple/';
     $fixtures_name = 'apple';
     $zip_file = _PS_ROOT_DIR_ . '/download/fixtures.zip';
     $temp_dir = _PS_ROOT_DIR_ . '/download/fixtures/';
     // try to download fixtures if no low memory mode
     if ($entity === null) {
         if (Tools::copy('http://api.prestashop.com/fixtures/' . $data['shop_country'] . '/' . $data['shop_activity'] . '/fixtures.zip', $zip_file)) {
             Tools::deleteDirectory($temp_dir, true);
             if (Tools::ZipTest($zip_file)) {
                 if (Tools::ZipExtract($zip_file, $temp_dir)) {
                     $files = scandir($temp_dir);
                     if (count($files)) {
                         foreach ($files as $file) {
                             if (!preg_match('/^\\./', $file) && is_dir($temp_dir . $file . '/')) {
                                 $fixtures_path = $temp_dir . $file . '/';
                                 $fixtures_name = $file;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     // Load class (use fixture class if one exists, or use InstallXmlLoader)
     if (file_exists($fixtures_path . '/install.php')) {
         require_once $fixtures_path . '/install.php';
         $class = 'InstallFixtures' . Tools::toCamelCase($fixtures_name);
         if (!class_exists($class, false)) {
             $this->setError($this->language->l('Fixtures class "%s" not found', $class));
             return false;
         }
         $xml_loader = new $class();
         if (!$xml_loader instanceof InstallXmlLoader) {
             $this->setError($this->language->l('"%s" must be an instane of "InstallXmlLoader"', $class));
             return false;
         }
     } else {
         $xml_loader = new InstallXmlLoader();
     }
     // Install XML data (data/xml/ folder)
     $xml_loader->setFixturesPath($fixtures_path);
     if (isset($this->xml_loader_ids) && $this->xml_loader_ids) {
         $xml_loader->setIds($this->xml_loader_ids);
     }
     $languages = array();
     foreach (Language::getLanguages(false) as $lang) {
         $languages[$lang['id_lang']] = $lang['iso_code'];
     }
     $xml_loader->setLanguages($languages);
     if ($entity) {
         $xml_loader->populateEntity($entity);
     } else {
         $xml_loader->populateFromXmlFiles();
         Tools::deleteDirectory($temp_dir, true);
         @unlink($zip_file);
     }
     if ($errors = $xml_loader->getErrors()) {
         $this->setError($errors);
         return false;
     }
     // IDS from xmlLoader are stored in order to use them for fixtures
     $this->xml_loader_ids = $xml_loader->getIds();
     unset($xml_loader);
     // Index products in search tables
     Search::indexation(true);
     return true;
 }
Example #2
0
 public function processImportTheme()
 {
     $this->display = 'importtheme';
     if (defined('_PS_HOST_MODE_')) {
         return true;
     }
     if (isset($_FILES['themearchive']) && isset($_POST['filename']) && Tools::isSubmit('theme_archive_server')) {
         $uniqid = uniqid();
         $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR;
         mkdir($sandbox);
         $archive_uploaded = false;
         if (Tools::getValue('filename') != '') {
             if ($_FILES['themearchive']['error'] || !file_exists($_FILES['themearchive']['tmp_name'])) {
                 $this->errors[] = sprintf($this->l('An error has occurred during the file upload (%s)'), $_FILES['themearchive']['error']);
             } elseif (substr($_FILES['themearchive']['name'], -4) != '.zip') {
                 $this->errors[] = $this->l('Only zip files are allowed');
             } elseif (!move_uploaded_file($_FILES['themearchive']['tmp_name'], $sandbox . 'uploaded.zip')) {
                 $this->errors[] = $this->l('An error has occurred during the file copy.');
             } elseif (Tools::ZipTest($sandbox . 'uploaded.zip')) {
                 $archive_uploaded = true;
             } else {
                 $this->errors[] = $this->l('Zip file seems to be broken');
             }
         } elseif (Tools::getValue('themearchiveUrl') != '') {
             if (!Validate::isModuleUrl($url = Tools::getValue('themearchiveUrl'), $this->errors)) {
                 $this->errors[] = $this->l('Only zip files are allowed');
             } elseif (!move_uploaded_file($url, $sandbox . 'uploaded.zip')) {
                 $this->errors[] = $this->l('Error during the file download');
             } elseif (Tools::ZipTest($sandbox . 'uploaded.zip')) {
                 $archive_uploaded = true;
             } else {
                 $this->errors[] = $this->l('Zip file seems to be broken');
             }
         } elseif (Tools::getValue('theme_archive_server') != '') {
             $filename = _PS_ALL_THEMES_DIR_ . Tools::getValue('theme_archive_server');
             if (substr($filename, -4) != '.zip') {
                 $this->errors[] = $this->l('Only zip files are allowed');
             } elseif (!copy($filename, $sandbox . 'uploaded.zip')) {
                 $this->errors[] = $this->l('An error has occurred during the file copy.');
             } elseif (Tools::ZipTest($sandbox . 'uploaded.zip')) {
                 $archive_uploaded = true;
             } else {
                 $this->errors[] = $this->l('Zip file seems to be broken');
             }
         } else {
             $this->errors[] = $this->l('You must upload or enter a location of your zip');
         }
         if ($archive_uploaded) {
             if (!Tools::ZipExtract($sandbox . '/uploaded.zip', $sandbox . 'uploaded/')) {
                 $this->errors[] = $this->l('Error during zip extraction');
             } else {
                 if (!$this->checkXmlFields($sandbox)) {
                     $this->errors[] = $this->l('Bad configuration file');
                 } else {
                     $imported_theme = $this->importThemeXmlConfig(simplexml_load_file($sandbox . 'uploaded/Config.xml'));
                     if (Validate::isLoadedObject($imported_theme)) {
                         if (!copy($sandbox . 'uploaded/Config.xml', _PS_ROOT_DIR_ . '/config/xml/themes/' . $imported_theme->directory . '.xml')) {
                             $this->errors[] = $this->l('Can\'t copy configuration file');
                         }
                         $target_dir = _PS_ALL_THEMES_DIR_ . $imported_theme->directory;
                         $theme_doc_dir = $target_dir . '/docs/';
                         if (file_exists($theme_doc_dir)) {
                             Tools::deleteDirectory($theme_doc_dir);
                         }
                         $this->recurseCopy($sandbox . 'uploaded/themes/' . $imported_theme->directory, $target_dir);
                         $this->recurseCopy($sandbox . 'uploaded/doc/', $theme_doc_dir);
                         $this->recurseCopy($sandbox . 'uploaded/modules/', _PS_MODULE_DIR_);
                     } else {
                         $this->errors[] = $imported_theme;
                     }
                 }
             }
         }
         Tools::deleteDirectory($sandbox);
         if (count($this->errors) > 0) {
             $this->display = 'importtheme';
         } else {
             Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes') . '&conf=18');
         }
     }
 }
Example #3
0
 private function handleInformations()
 {
     if (Tools::isSubmit('submitImport1')) {
         if ($_FILES['themearchive']['error'] || !file_exists($_FILES['themearchive']['tmp_name'])) {
             $this->errors[] = sprintf($this->l('An error has occurred during the file upload (%s)'), $_FILES['themearchive']['error']);
         } elseif (substr($_FILES['themearchive']['name'], -4) != '.zip') {
             $this->errors[] = $this->l('Only zip files are allowed');
         } elseif (!rename($_FILES['themearchive']['tmp_name'], ARCHIVE_NAME)) {
             $this->errors[] = $this->l('An error has occurred during the file copy.');
         } elseif (Tools::ZipTest(ARCHIVE_NAME)) {
             $this->page = 2;
         } else {
             $this->errors[] = $this->l('Zip file seems to be broken');
         }
     } elseif (Tools::isSubmit('submitImport2')) {
         if (!Validate::isModuleUrl($url = Tools::getValue('linkurl'), $this->errors)) {
             // $tmp is not used, because we don't care about the error output of isModuleUrl
             $this->errors[] = $this->l('Only zip files are allowed');
         } elseif (!copy($url, ARCHIVE_NAME)) {
             $this->errors[] = $this->l('Error during the file download');
         } elseif (Tools::ZipTest(ARCHIVE_NAME)) {
             $this->page = 2;
         } else {
             $this->errors[] = $this->l('Zip file seems to be broken');
         }
     } elseif (Tools::isSubmit('submitImport3')) {
         $filename = _IMPORT_FOLDER_ . Tools::getValue('ArchiveName');
         if (substr($filename, -4) != '.zip') {
             $this->errors[] = $this->l('Only zip files are allowed');
         } elseif (!copy($filename, ARCHIVE_NAME)) {
             $this->errors[] = $this->l('An error has occurred during the file copy.');
         } elseif (Tools::ZipTest(ARCHIVE_NAME)) {
             $this->page = 2;
         } else {
             $this->errors[] = $this->l('Zip file seems to be broken');
         }
     } elseif (Tools::isSubmit('prevThemes')) {
         $this->page = 2;
     } elseif (Tools::isSubmit('submitThemes')) {
         $this->page = 3;
     } elseif (Tools::isSubmit('submitModules')) {
         $this->page = 4;
     }
     if ($this->page == 2 && file_exists(ARCHIVE_NAME)) {
         if (!Tools::ZipExtract(ARCHIVE_NAME, _IMPORT_FOLDER_)) {
             $this->errors[] = $this->l('Error during zip extraction');
             $this->page = 1;
         }
     }
     if (file_exists(ARCHIVE_NAME)) {
         @unlink(ARCHIVE_NAME);
     }
     if ($this->page != 1) {
         if (!self::checkXmlFields()) {
             $this->errors[] = $this->l('Bad configuration file');
             $this->page = 1;
         } else {
             return;
         }
     }
     self::deleteTmpFiles();
 }
 private function handleInformations()
 {
     if (Tools::isSubmit('submitImport1')) {
         if (isset($_FILES['themearchive']['error']) && $_FILES['themearchive']['error'] == 1) {
             $uploadMaxSize = (int) str_replace('M', '', ini_get('upload_max_filesize'));
             $postMaxSize = (int) str_replace('M', '', ini_get('post_max_size'));
             $maxSize = $uploadMaxSize < $postMaxSize ? $uploadMaxSize : $postMaxSize;
             $this->errors[] = parent::displayError($this->l('An error occurred during logo copy. Image size must be below') . ' ' . $maxSize . 'M.');
         } elseif ($_FILES['themearchive']['error'] || !file_exists($_FILES['themearchive']['tmp_name'])) {
             $this->errors[] = parent::displayError($this->l('An error has occurred during the file upload.'));
         } elseif (substr($_FILES['themearchive']['name'], -4) != '.zip') {
             $this->errors[] = parent::displayError($this->l('Only zip files are allowed'));
         } elseif (!rename($_FILES['themearchive']['tmp_name'], ARCHIVE_NAME)) {
             $this->errors[] = parent::displayError($this->l('An error has occurred during the file copy.'));
         } elseif (Tools::ZipTest(ARCHIVE_NAME)) {
             $this->page = 2;
         } else {
             $this->errors[] = parent::displayError($this->l('Zip file seems to be broken'));
         }
     } elseif (Tools::isSubmit('submitImport2')) {
         if (!Validate::isModuleUrl($url = Tools::getValue('linkurl'), $this->errors)) {
             // $tmp is not used, because we don't care about the error output of isModuleUrl
             $this->errors[] = parent::displayError($this->l('Only zip files are allowed'));
         } elseif (!copy($url, ARCHIVE_NAME)) {
             $this->errors[] = parent::displayError($this->l('Error during the file download'));
         } elseif (Tools::ZipTest(ARCHIVE_NAME)) {
             $this->errors[] = parent::displayError($this->l('Zip file seems to be broken'));
         } else {
             $this->page = 2;
         }
     } elseif (Tools::isSubmit('submitImport3')) {
         $filename = _IMPORT_FOLDER_ . Tools::getValue('ArchiveName');
         if (substr($filename, -4) != '.zip') {
             $this->errors[] = parent::displayError($this->l('Only zip files are allowed'));
         } elseif (!copy($filename, ARCHIVE_NAME)) {
             $this->errors[] = parent::displayError($this->l('An error has occurred during the file copy.'));
         } elseif (Tools::ZipTest(ARCHIVE_NAME)) {
             $this->page = 2;
         } else {
             $this->errors[] = parent::displayError($this->l('Zip file seems to be broken'));
         }
     } elseif (Tools::isSubmit('prevThemes')) {
         $this->page = 2;
     } elseif (Tools::isSubmit('submitThemes')) {
         $this->page = 3;
     } elseif (Tools::isSubmit('submitModules')) {
         $this->page = 4;
     }
     if ($this->page == 2 && file_exists(ARCHIVE_NAME)) {
         if (!Tools::ZipExtract(ARCHIVE_NAME, _IMPORT_FOLDER_)) {
             $this->errors[] = parent::displayError($this->l('Error during zip extraction'));
             $this->page = 1;
         }
     }
     if (file_exists(ARCHIVE_NAME)) {
         @unlink(ARCHIVE_NAME);
     }
     if ($this->page != 1) {
         if (!self::checkXmlFields()) {
             $this->errors[] = parent::displayError($this->l('Bad configuration file'));
             $this->page = 1;
         } else {
             return;
         }
     }
     self::deleteTmpFiles();
 }
 public function processImportTheme()
 {
     $this->display = 'importtheme';
     if ($this->context->mode == Context::MODE_HOST) {
         return true;
     }
     if (isset($_FILES['themearchive']) && isset($_POST['filename']) && Tools::isSubmit('theme_archive_server')) {
         $uniqid = uniqid();
         $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR;
         mkdir($sandbox);
         $archive_uploaded = false;
         if (Tools::getValue('filename') != '') {
             $uploader = new Uploader('themearchive');
             $uploader->setAcceptTypes(array('zip'));
             $uploader->setSavePath($sandbox);
             $file = $uploader->process(Theme::UPLOADED_THEME_DIR_NAME . '.zip');
             if ($file[0]['error'] === 0) {
                 if (Tools::ZipTest($sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                     $archive_uploaded = true;
                 } else {
                     $this->errors[] = $this->l('Zip file seems to be broken');
                 }
             } else {
                 $this->errors[] = $file[0]['error'];
             }
         } elseif (Tools::getValue('themearchiveUrl') != '') {
             if (!Validate::isModuleUrl($url = Tools::getValue('themearchiveUrl'), $this->errors)) {
                 $this->errors[] = $this->l('Only zip files are allowed');
             } elseif (!Tools::copy($url, $sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                 $this->errors[] = $this->l('Error during the file download');
             } elseif (Tools::ZipTest($sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                 $archive_uploaded = true;
             } else {
                 $this->errors[] = $this->l('Zip file seems to be broken');
             }
         } elseif (Tools::getValue('theme_archive_server') != '') {
             $filename = _PS_ALL_THEMES_DIR_ . Tools::getValue('theme_archive_server');
             if (substr($filename, -4) != '.zip') {
                 $this->errors[] = $this->l('Only zip files are allowed');
             } elseif (!copy($filename, $sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                 $this->errors[] = $this->l('An error has occurred during the file copy.');
             } elseif (Tools::ZipTest($sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                 $archive_uploaded = true;
             } else {
                 $this->errors[] = $this->l('Zip file seems to be broken');
             }
         } else {
             $this->errors[] = $this->l('You must upload or enter a location of your zip');
         }
         if ($archive_uploaded) {
             if ($this->extractTheme($sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip', $sandbox)) {
                 $this->installTheme(Theme::UPLOADED_THEME_DIR_NAME, $sandbox);
             }
         }
         Tools::deleteDirectory($sandbox);
         if (count($this->errors) > 0) {
             $this->display = 'importtheme';
         } else {
             Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes') . '&conf=18');
         }
     }
 }
Example #6
0
 public static function install_theme_zip($themeZip)
 {
     //test zip
     if (!Tools::ZipTest($themeZip)) {
         echo "Error, {$themeZip} is not a valid Zip archive\n";
         return false;
     }
     $uniqid = uniqid();
     $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR;
     mkdir($sandbox);
     if (!Tools::ZipExtract($themeZip, $sandbox)) {
         echo "Could not extract zip file\n";
         return false;
     }
     //process install
     self::install_theme_files($sandbox);
 }
Example #7
0
 function psmDownloadModule($module_name)
 {
     $success = false;
     if (!is_dir(_PS_MODULE_DIR_ . $module_name)) {
         $content = Tools::file_get_contents('http://store.psandmore.com/query/download.php?ps=' . _PS_VERSION_ . '&module=' . $module_name);
         if ($content) {
             $zip_file = _PS_MODULE_DIR_ . $module_name . '.zip';
             Tools::deleteFile($zip_file);
             if (file_put_contents($zip_file, $content) !== false) {
                 if (Tools::ZipTest($zip_file)) {
                     $success = Tools::ZipExtract($zip_file, _PS_MODULE_DIR_);
                 }
                 Tools::deleteFile($zip_file);
             }
         }
     }
     return $success;
 }