forked from ZwiiCMS-Team/ZwiiCMS
custom_copy devient copy Dir dans core + check backup copy error
This commit is contained in:
parent
d3387330bd
commit
f67de97eb9
@ -1031,6 +1031,39 @@ class common {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Copie récursive de dossiers
|
||||
* @param string $src dossier source
|
||||
* @param string $dst dossier destination
|
||||
* @return bool
|
||||
*/
|
||||
public function copyDir($src, $dst) {
|
||||
// Ouvrir le dossier source
|
||||
$dir = opendir($src);
|
||||
// Créer le dossier de destination
|
||||
if (!is_dir($dst))
|
||||
$success = mkdir($dst);
|
||||
else
|
||||
$success = true;
|
||||
|
||||
// Boucler dans le dossier source en l'absence d'échec de lecture écriture
|
||||
while( $success
|
||||
AND $file = readdir($dir) ) {
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
if ( is_dir($src . '/' . $file) ){
|
||||
// Appel récursif des sous-dossiers
|
||||
$success = $this->copyTree($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
else {
|
||||
$success = copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Génère une archive d'un dossier et des sous-dossiers
|
||||
* @param string fileName path et nom de l'archive
|
||||
|
@ -155,7 +155,7 @@ class addon extends common {
|
||||
// Nouvelle installation ou mise à jour du module
|
||||
if( ! $moduleInstal || $validMaj ){
|
||||
// Copie récursive des dossiers
|
||||
$this -> custom_copy( self::TEMP_DIR . $tempFolder, './' );
|
||||
$this->copyDir( self::TEMP_DIR . $tempFolder, './' );
|
||||
$success = true;
|
||||
if( ! $moduleInstal ){
|
||||
$notification = 'Module '.$moduleName.' installé';
|
||||
@ -461,7 +461,7 @@ class addon extends common {
|
||||
// Export des données localisées dans le dossier de données du module
|
||||
if ($infoModules[$this->getUrl(2)]['dataDirectory'] &&
|
||||
is_dir($infoModules[$this->getUrl(2)]['dataDirectory'])) {
|
||||
$this->custom_copy ($infoModules[$this->getUrl(2)]['dataDirectory'], $tmpFolder . '/' . $moduleDir);
|
||||
$this->copyDir ($infoModules[$this->getUrl(2)]['dataDirectory'], $tmpFolder . '/' . $moduleDir);
|
||||
}
|
||||
}
|
||||
// Enregistrement des pages dans le dossier de langue identique à module
|
||||
@ -553,7 +553,7 @@ class addon extends common {
|
||||
}
|
||||
|
||||
// Import des fichiers placés ailleurs que dans les dossiers localisés.
|
||||
$this->custom_copy (self::TEMP_DIR . $tempFolder,self::DATA_DIR );
|
||||
$this->copyDir (self::TEMP_DIR . $tempFolder,self::DATA_DIR );
|
||||
|
||||
// Supprimer le dossier temporaire
|
||||
$this->removeDir(self::TEMP_DIR . $tempFolder);
|
||||
@ -581,31 +581,4 @@ class addon extends common {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copie récursive de dossiers
|
||||
*
|
||||
*/
|
||||
private function custom_copy($src, $dst) {
|
||||
// open the source directory
|
||||
$dir = opendir($src);
|
||||
// Make the destination directory if not exist
|
||||
if (!is_dir($dst)) {
|
||||
mkdir($dst);
|
||||
}
|
||||
// Loop through the files in source directory
|
||||
while( $file = readdir($dir) ) {
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
if ( is_dir($src . '/' . $file) ){
|
||||
// Recursively calling custom copy function
|
||||
// for sub directory
|
||||
$this -> custom_copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
else {
|
||||
copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -743,12 +743,16 @@ class config extends common {
|
||||
if (!is_dir(self::FILE_DIR.'source/backup')) {
|
||||
mkdir(self::FILE_DIR.'source/backup');
|
||||
}
|
||||
$this->custom_copy(self::BACKUP_DIR, self::FILE_DIR . 'source/backup' );
|
||||
$success = $this->copyDir(self::BACKUP_DIR, self::FILE_DIR . 'source/backup' );
|
||||
// Effacer htaccess
|
||||
if (file_exists(self::FILE_DIR.'source/backup/.htaccess')) {
|
||||
unlink(self::FILE_DIR.'source/backup/.htaccess');
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config/advanced',
|
||||
'notification' => 'Copie terminée',
|
||||
'state' => true
|
||||
'notification' => $success ? 'Copie terminée avec succès' : 'Echec de la copie',
|
||||
'state' => $success
|
||||
]);
|
||||
}
|
||||
|
||||
@ -773,31 +777,4 @@ class config extends common {
|
||||
}
|
||||
return $newArray;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copie récursive de dossiers
|
||||
*
|
||||
*/
|
||||
private function custom_copy($src, $dst) {
|
||||
// open the source directory
|
||||
$dir = opendir($src);
|
||||
// Make the destination directory if not exist
|
||||
if (!is_dir($dst)) {
|
||||
mkdir($dst);
|
||||
}
|
||||
// Loop through the files in source directory
|
||||
while( $file = readdir($dir) ) {
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
if ( is_dir($src . '/' . $file) ){
|
||||
// Recursively calling custom copy function
|
||||
// for sub directory
|
||||
$this -> custom_copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
else {
|
||||
copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user