[-] MO : #PSCFV-2356 - Theme installor - Check one theme at least is selected before exportation

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@15369 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mDeflotte committed 2012-05-18 13:01:26 +00:00
1 parent b22d4f7661
commit fd43da9f1c
1 file changed
+38 -31
+38 -31
View File
@@ -106,7 +106,7 @@ class ThemeInstallator extends Module
{ {
if (is_dir($dirname.'/'.$file)) if (is_dir($dirname.'/'.$file))
self::deleteDirectory($dirname.'/'.$file); self::deleteDirectory($dirname.'/'.$file);
else if (file_exists($dirname.'/'.$file)) elseif (file_exists($dirname.'/'.$file))
unlink($dirname.'/'.$file); unlink($dirname.'/'.$file);
} }
rmdir($dirname); rmdir($dirname);
@@ -123,7 +123,7 @@ class ThemeInstallator extends Module
{ {
if (is_dir($src.'/'.$file)) if (is_dir($src.'/'.$file))
self::recurseCopy($src.'/'.$file, $dst.'/'.$file); self::recurseCopy($src.'/'.$file, $dst.'/'.$file);
else if (is_readable($src.'/'.$file) && $file != 'Thumbs.db' && $file != '.DS_Store' && substr($file, -1) != '~') elseif (is_readable($src.'/'.$file) && $file != 'Thumbs.db' && $file != '.DS_Store' && substr($file, -1) != '~')
copy($src.'/'.$file, $dst.'/'.$file); copy($src.'/'.$file, $dst.'/'.$file);
} }
closedir($dir); closedir($dir);
@@ -220,43 +220,43 @@ class ThemeInstallator extends Module
{ {
if ($_FILES['themearchive']['error'] || !file_exists($_FILES['themearchive']['tmp_name'])) if ($_FILES['themearchive']['error'] || !file_exists($_FILES['themearchive']['tmp_name']))
$this->errors[] = parent::displayError($this->l('An error has occurred during the file upload.')); $this->errors[] = parent::displayError($this->l('An error has occurred during the file upload.'));
else if (substr($_FILES['themearchive']['name'], -4) != '.zip') elseif (substr($_FILES['themearchive']['name'], -4) != '.zip')
$this->errors[] = parent::displayError($this->l('Only zip files are allowed')); $this->errors[] = parent::displayError($this->l('Only zip files are allowed'));
else if (!rename($_FILES['themearchive']['tmp_name'], ARCHIVE_NAME)) elseif (!rename($_FILES['themearchive']['tmp_name'], ARCHIVE_NAME))
$this->errors[] = parent::displayError($this->l('An error has occurred during the file copy.')); $this->errors[] = parent::displayError($this->l('An error has occurred during the file copy.'));
else if (Tools::ZipTest(ARCHIVE_NAME)) elseif (Tools::ZipTest(ARCHIVE_NAME))
$this->page = 2; $this->page = 2;
else else
$this->errors[] = parent::displayError($this->l('Zip file seems to be broken')); $this->errors[] = parent::displayError($this->l('Zip file seems to be broken'));
} }
else if (Tools::isSubmit('submitImport2')) elseif (Tools::isSubmit('submitImport2'))
{ {
if (!Validate::isModuleUrl($url = Tools::getValue('linkurl'), $tmp)) // $tmp is not used, because we don't care about the error output of isModuleUrl if (!Validate::isModuleUrl($url = Tools::getValue('linkurl'), $tmp)) // $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')); $this->errors[] = parent::displayError($this->l('Only zip files are allowed'));
else if (!copy($url, ARCHIVE_NAME)) elseif (!copy($url, ARCHIVE_NAME))
$this->errors[] = parent::displayError($this->l('Error during the file download')); $this->errors[] = parent::displayError($this->l('Error during the file download'));
else if (Tools::ZipTest(ARCHIVE_NAME)) elseif (Tools::ZipTest(ARCHIVE_NAME))
$this->errors[] = parent::displayError($this->l('Zip file seems to be broken')); $this->errors[] = parent::displayError($this->l('Zip file seems to be broken'));
else else
$this->page = 2; $this->page = 2;
} }
else if (Tools::isSubmit('submitImport3')) elseif (Tools::isSubmit('submitImport3'))
{ {
$filename = _IMPORT_FOLDER_.Tools::getValue('ArchiveName'); $filename = _IMPORT_FOLDER_.Tools::getValue('ArchiveName');
if (substr($filename, -4) != '.zip') if (substr($filename, -4) != '.zip')
$this->errors[] = parent::displayError($this->l('Only zip files are allowed')); $this->errors[] = parent::displayError($this->l('Only zip files are allowed'));
else if (!copy($filename, ARCHIVE_NAME)) elseif (!copy($filename, ARCHIVE_NAME))
$this->errors[] = parent::displayError($this->l('An error has occurred during the file copy.')); $this->errors[] = parent::displayError($this->l('An error has occurred during the file copy.'));
else if (Tools::ZipTest(ARCHIVE_NAME)) elseif (Tools::ZipTest(ARCHIVE_NAME))
$this->page = 2; $this->page = 2;
else else
$this->errors[] = parent::displayError($this->l('Zip file seems to be broken')); $this->errors[] = parent::displayError($this->l('Zip file seems to be broken'));
} }
else if (Tools::isSubmit('prevThemes')) elseif (Tools::isSubmit('prevThemes'))
$this->page = 2; $this->page = 2;
else if (Tools::isSubmit('submitThemes')) elseif (Tools::isSubmit('submitThemes'))
$this->page = 3; $this->page = 3;
else if (Tools::isSubmit('submitModules')) elseif (Tools::isSubmit('submitModules'))
$this->page = 4; $this->page = 4;
if ($this->page == 2 && file_exists(ARCHIVE_NAME)) if ($this->page == 2 && file_exists(ARCHIVE_NAME))
{ {
@@ -309,11 +309,18 @@ class ThemeInstallator extends Module
if (Tools::isSubmit('submitExport') && $this->error === false && $this->checkPostedDatas() == true) if (Tools::isSubmit('submitExport') && $this->error === false && $this->checkPostedDatas() == true)
{ {
self::getThemeVariations(); self::getThemeVariations();
self::getDocumentation();
self::getHookState(); // Check variations exists
self::getImageState(); if (empty($this->variations))
self::generateXML(); $this->_html .= parent::displayError($this->l('You must select at least one theme'));
self::generateArchive(); else
{
self::getDocumentation();
self::getHookState();
self::getImageState();
self::generateXML();
self::generateArchive();
}
} }
self::AuthorInformationForm(); self::AuthorInformationForm();
self::ModulesInformationForm(); self::ModulesInformationForm();
@@ -353,7 +360,7 @@ class ThemeInstallator extends Module
self::_displayForm4(); self::_displayForm4();
break; break;
} }
return join($this->errors, '').$this->_msg.$this->_html; return implode($this->errors, '').$this->_msg.$this->_html;
} }
/* /*
@@ -394,9 +401,9 @@ class ThemeInstallator extends Module
{ {
if (strval($row['action']) == 'install' && !in_array(strval($row['name']), $this->native_modules)) if (strval($row['action']) == 'install' && !in_array(strval($row['name']), $this->native_modules))
$this->to_install[] = strval($row['name']); $this->to_install[] = strval($row['name']);
else if (strval($row['action']) == 'enable') elseif (strval($row['action']) == 'enable')
$this->to_enable[] = strval($row['name']); $this->to_enable[] = strval($row['name']);
else if (strval($row['action']) == 'disable') elseif (strval($row['action']) == 'disable')
$this->to_disable[] = strval($row['name']); $this->to_disable[] = strval($row['name']);
} }
} }
@@ -478,7 +485,7 @@ class ThemeInstallator extends Module
UPDATE `'._DB_PREFIX_.'module` UPDATE `'._DB_PREFIX_.'module`
SET `active`= 1 SET `active`= 1
WHERE `name` = \''.pSQL($row).'\''); WHERE `name` = \''.pSQL($row).'\'');
else if (!$obj || !$obj->install()) elseif (!$obj || !$obj->install())
continue; continue;
Db::getInstance()->execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.$shopID.')'); Db::getInstance()->execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.$shopID.')');
$msg .= '<i>- '.pSQL($row).'</i><br />'; $msg .= '<i>- '.pSQL($row).'</i><br />';
@@ -530,7 +537,7 @@ class ThemeInstallator extends Module
WHERE `name` = \''.pSQL($row).'\''); WHERE `name` = \''.pSQL($row).'\'');
Db::getInstance()->execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.$shopID.')'); Db::getInstance()->execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.$shopID.')');
} }
else if (!is_object($obj) || !$obj->install()) elseif (!is_object($obj) || !$obj->install())
continue ; continue ;
if ($flag++ == 0) if ($flag++ == 0)
$msg .= '<b>'.$this->l('The following modules have been enabled').' :</b><br />'; $msg .= '<b>'.$this->l('The following modules have been enabled').' :</b><br />';
@@ -865,7 +872,7 @@ class ThemeInstallator extends Module
if ($row != '.' && $row != '..') if ($row != '.' && $row != '..')
$this->archiveThisFile($obj, $row, $serverPath.$file.'/', $archivePath.$file.'/'); $this->archiveThisFile($obj, $row, $serverPath.$file.'/', $archivePath.$file.'/');
} }
else if (!$obj->addFile($serverPath.$file, $archivePath.$file)) elseif (!$obj->addFile($serverPath.$file, $archivePath.$file))
$this->error = true; $this->error = true;
} }
@@ -1045,7 +1052,7 @@ class ThemeInstallator extends Module
else else
$this->to_disable[] = $array['name']; $this->to_disable[] = $array['name'];
} }
else if ($array['active'] == 1) elseif ($array['active'] == 1)
$this->to_install[] = $array['name']; $this->to_install[] = $array['name'];
} }
foreach ($this->native_modules as $str) foreach ($this->native_modules as $str)
@@ -1134,9 +1141,9 @@ class ThemeInstallator extends Module
if ($mail && !preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#', $mail)) if ($mail && !preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#', $mail))
$this->_html .= parent::displayError($this->l('There is an error in your e-mail syntax!')); $this->_html .= parent::displayError($this->l('There is an error in your e-mail syntax!'));
else if ($website && (!Validate::isURL($website) || !Validate::isAbsoluteUrl($website))) elseif ($website && (!Validate::isURL($website) || !Validate::isAbsoluteUrl($website)))
$this->_html .= parent::displayError($this->l('There is an error in your URL syntax!')); $this->_html .= parent::displayError($this->l('There is an error in your URL syntax!'));
else if (!$this->checkVersionsAndCompatibility() || !$this->checkNames() || !$this->checkDocumentation()) elseif (!$this->checkVersionsAndCompatibility() || !$this->checkNames() || !$this->checkDocumentation())
return false; return false;
else else
return true; return true;
@@ -1159,9 +1166,9 @@ class ThemeInstallator extends Module
if (!in_array($extension, $extensions)) if (!in_array($extension, $extensions))
$this->_html .= parent::displayError($this->l('File extension must be .txt or .pdf')); $this->_html .= parent::displayError($this->l('File extension must be .txt or .pdf'));
else if ($_FILES['mydoc_'.$count]['error'] > 0 || $_FILES['mydoc_'.$count]['size'] > 1048576) elseif ($_FILES['mydoc_'.$count]['error'] > 0 || $_FILES['mydoc_'.$count]['size'] > 1048576)
$this->_html .= parent::displayError($this->l('An error occurred during documentation upload')); $this->_html .= parent::displayError($this->l('An error occurred during documentation upload'));
else if (!$name || !Validate::isGenericName($name) || strlen($name) > MAX_NAME_LENGTH) elseif (!$name || !Validate::isGenericName($name) || strlen($name) > MAX_NAME_LENGTH)
$this->_html .= parent::displayError($this->l('Please enter a valid documentation name')); $this->_html .= parent::displayError($this->l('Please enter a valid documentation name'));
} }
if ($this->error == true) if ($this->error == true)
@@ -1180,7 +1187,7 @@ class ThemeInstallator extends Module
if (!$author || !Validate::isGenericName($author) || strlen($author) > MAX_NAME_LENGTH) if (!$author || !Validate::isGenericName($author) || strlen($author) > MAX_NAME_LENGTH)
$this->_html .= parent::displayError($this->l('Please enter a valid author name')); $this->_html .= parent::displayError($this->l('Please enter a valid author name'));
else if (!$name || !Validate::isGenericName($name) || strlen($name) > MAX_NAME_LENGTH) elseif (!$name || !Validate::isGenericName($name) || strlen($name) > MAX_NAME_LENGTH)
$this->_html .= parent::displayError($this->l('Please enter a valid theme name')); $this->_html .= parent::displayError($this->l('Please enter a valid theme name'));
while ($this->error === false && Tools::isSubmit('myvar_'.++$count)) while ($this->error === false && Tools::isSubmit('myvar_'.++$count))
{ {