v9.0.0 : optimisation code export
This commit is contained in:
parent
5cd358633b
commit
7eea09ece5
@ -448,31 +448,10 @@ class theme extends common {
|
|||||||
*/
|
*/
|
||||||
public function manage() {
|
public function manage() {
|
||||||
if($this->isPost() ) {
|
if($this->isPost() ) {
|
||||||
if ($this->getInput('themeManageImport') !== '') {
|
$archive = $this->getInput('themeManageImport', helper::FILTER_STRING_SHORT, true);
|
||||||
if ($this->import($this->getInput('themeManageImport'))) {
|
echo $archive;
|
||||||
|
|
||||||
// import ok
|
// import ok
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Thème ' . $this->getInput('themeManageImport'). ' importé',
|
|
||||||
'redirect' => helper::baseUrl() . 'theme',
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Archive incorrecte',
|
|
||||||
'redirect' => helper::baseUrl() . 'theme',
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Error ',
|
|
||||||
'redirect' => helper::baseUrl() . 'theme',
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
@ -487,87 +466,22 @@ class theme extends common {
|
|||||||
*/
|
*/
|
||||||
public function export() {
|
public function export() {
|
||||||
// Creation du dossier
|
// Creation du dossier
|
||||||
$genRandom = date('dmYhms').'-'.rand(100,999);
|
$zipFilename = 'theme-'.date('dmYhms').'-'.rand(100,999).'.zip';
|
||||||
$zipFilename = $genRandom . '.zip';
|
|
||||||
$folderTemp = 'site/tmp/theme-' . $genRandom . '/';
|
|
||||||
$folderSource = $folderTemp . 'site/file/source/';
|
|
||||||
$folderData = $folderTemp . 'site/data/';
|
|
||||||
if (mkdir($folderTemp,0755,TRUE) and mkdir($folderData,0755,TRUE) AND mkdir($folderSource,0755,TRUE) ) {
|
|
||||||
// Dossier créé avec succès, copie du thème
|
|
||||||
if (copy( 'site/data/theme.json' , $folderData . 'theme.json')){
|
|
||||||
// Copie réalisée avec succès copie des images du thème
|
|
||||||
// Copie image de body
|
|
||||||
if ($this->getData(['theme','body','image']) !== '') {
|
|
||||||
if ( !mkdir ($folderSource . dirname($this->getData(['theme','body','image'])),0755,TRUE) OR
|
|
||||||
!copy('site/file/source/'.$this->getData(['theme','body','image']), $folderSource . $this->getData(['theme','body','image']))) {
|
|
||||||
// Erreur de copie des images
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Erreur lors de la création de l\'export',
|
|
||||||
'redirect' => helper::baseUrl() . 'theme/manage',
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Copie image du header
|
|
||||||
if ($this->getData(['theme','header','image']) !== '') {
|
|
||||||
// Le dossier est-il créé ?
|
|
||||||
if (!file_exists($folderSource . dirname($this->getData(['theme','header','image'])))) {
|
|
||||||
if ( !mkdir ($folderSource . dirname($this->getData(['theme','header','image'])),0755,TRUE)) {
|
|
||||||
// Erreur création dossier
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Erreur lors de la création de l\'export',
|
|
||||||
'redirect' => helper::baseUrl() . 'theme/manage',
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!copy('site/file/source/'.$this->getData(['theme','header','image']), $folderSource . $this->getData(['theme','header','image']))) {
|
|
||||||
// Erreur de copie des images
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Erreur lors de la création de l\'export',
|
|
||||||
'redirect' => helper::baseUrl() . 'theme/manage',
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Erreur de copy du thème
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Erreur lors de la création de l\'export',
|
|
||||||
'redirect' => helper::baseUrl() . 'theme/manage',
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Erreur création du dossier temporaire
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Erreur lors de la création de l\'export',
|
|
||||||
'redirect' => helper::baseUrl() . 'theme/manage',
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
// Création du ZIP
|
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
$zip->open('site/tmp/' . $zipFilename, ZipArchive::CREATE | ZipArchive::OVERWRITE );
|
if ($zip->open('site/tmp/' . $zipFilename, ZipArchive::CREATE | ZipArchive::OVERWRITE ) === TRUE) {
|
||||||
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folderTemp), RecursiveIteratorIterator::LEAVES_ONLY);
|
$zip->addFile('site/data/theme.json','site/data/theme.json');
|
||||||
foreach ($files as $name => $file)
|
if ($this->getData(['theme','body','image']) !== '' ) {
|
||||||
{
|
$zip->addFile('site/file/source/'.$this->getData(['theme','body','image']),
|
||||||
if (!$file->isDir())
|
'site/file/source/'.$this->getData(['theme','body','image'])
|
||||||
{
|
);
|
||||||
// Get real and relative path for current file
|
|
||||||
$filePath = $file->getRealPath();
|
|
||||||
$relativePath = substr($filePath, strlen($folderTemp)+3);
|
|
||||||
// Add current file to archive
|
|
||||||
$zip->addFile($filePath, $relativePath);
|
|
||||||
}
|
}
|
||||||
|
if ($this->getData(['theme','header','image']) !== '' ) {
|
||||||
|
$zip->addFile('site/file/source/'.$this->getData(['theme','header','image']),
|
||||||
|
'site/file/source/'.$this->getData(['theme','header','image'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$ret = $zip->close();
|
||||||
}
|
}
|
||||||
$zip->close();
|
|
||||||
// Téléchargement du ZIP
|
// Téléchargement du ZIP
|
||||||
header('Content-Description: File Transfer');
|
header('Content-Description: File Transfer');
|
||||||
header('Content-Type: application/octet-stream');
|
header('Content-Type: application/octet-stream');
|
||||||
@ -577,7 +491,6 @@ class theme extends common {
|
|||||||
readfile('site/tmp/' . $zipFilename);
|
readfile('site/tmp/' . $zipFilename);
|
||||||
// Nettoyage du dossier
|
// Nettoyage du dossier
|
||||||
unlink ('site/tmp/' . $zipFilename);
|
unlink ('site/tmp/' . $zipFilename);
|
||||||
rmdir ($folderTemp);
|
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'display' => self::DISPLAY_RAW
|
'display' => self::DISPLAY_RAW
|
||||||
|
@ -8,11 +8,6 @@
|
|||||||
'value' => 'Retour'
|
'value' => 'Retour'
|
||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="col2 offset8">
|
|
||||||
<?php echo template::submit('themeImportSubmit', [
|
|
||||||
'value' => 'Importer'
|
|
||||||
]); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col6">
|
<div class="col6">
|
||||||
@ -26,11 +21,6 @@
|
|||||||
<?php echo template::submit('themeImportSubmit', [
|
<?php echo template::submit('themeImportSubmit', [
|
||||||
'value' => 'Importer'
|
'value' => 'Importer'
|
||||||
]); ?>
|
]); ?>
|
||||||
<p \>
|
|
||||||
<?php echo template::button('themeImport', [
|
|
||||||
'href' => helper::baseUrl() . 'theme/import',
|
|
||||||
'value' => 'Importer les données du thème'
|
|
||||||
]); ?>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user