forked from ZwiiCMS-Team/ZwiiCampus
backup ok
This commit is contained in:
parent
2abc9812dc
commit
7ac5d9589c
@ -35,7 +35,8 @@ class course extends common
|
|||||||
'userHistory' => self::GROUP_EDITOR,
|
'userHistory' => self::GROUP_EDITOR,
|
||||||
'usersHistoryExport' => self::GROUP_EDITOR,
|
'usersHistoryExport' => self::GROUP_EDITOR,
|
||||||
'userHistoryExport' => self::GROUP_EDITOR,
|
'userHistoryExport' => self::GROUP_EDITOR,
|
||||||
'courseBackup' => self::GROUP_ADMIN,
|
'backup' => self::GROUP_EDITOR,
|
||||||
|
'restore' => self::GROUP_EDITOR,
|
||||||
];
|
];
|
||||||
|
|
||||||
public static $courseAccess = [
|
public static $courseAccess = [
|
||||||
@ -108,15 +109,14 @@ class course extends common
|
|||||||
'help' => 'Éditer'
|
'help' => 'Éditer'
|
||||||
]),
|
]),
|
||||||
template::button('courseDownload' . $courseId, [
|
template::button('courseDownload' . $courseId, [
|
||||||
'href' => helper::baseUrl() . 'course/courseBackup/' . $courseId,
|
'href' => helper::baseUrl() . 'course/backup/' . $courseId,
|
||||||
'value' => template::ico('download'),
|
'value' => template::ico('download-cloud'),
|
||||||
'help' => 'Sauvegarder'
|
'help' => 'Sauvegarder'
|
||||||
]),
|
]),
|
||||||
template::button('courseUpload' . $courseId, [
|
template::button('courseUpload' . $courseId, [
|
||||||
'href' => helper::baseUrl() . 'course',
|
'href' => helper::baseUrl() . 'course/restore/',
|
||||||
'value' => template::ico('upload'),
|
'value' => template::ico('upload-cloud'),
|
||||||
'help' => 'Restaurer',
|
'help' => 'Restaurer',
|
||||||
'disabled' => true,
|
|
||||||
]),
|
]),
|
||||||
template::button('courseDelete' . $courseId, [
|
template::button('courseDelete' . $courseId, [
|
||||||
'class' => 'courseDelete buttonRed',
|
'class' => 'courseDelete buttonRed',
|
||||||
@ -1330,54 +1330,76 @@ class course extends common
|
|||||||
* Sauvegarde d'un cours sans option
|
* Sauvegarde d'un cours sans option
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function courseBackup()
|
public function backup()
|
||||||
{
|
{
|
||||||
$courseId = $this->getUrl(2);
|
|
||||||
|
|
||||||
// Participants avec historiques
|
// Accès refusé
|
||||||
$enrolment = $this->getData(['enrolment', $courseId]);
|
if (
|
||||||
// Générer un fichier dans le dossier de l'espace
|
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true
|
||||||
file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode([$courseId => $enrolment], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
) {
|
||||||
|
// Valeurs en sortie
|
||||||
|
$this->addOutput([
|
||||||
|
'access' => false
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$courseId = $this->getUrl(2);
|
||||||
|
|
||||||
// Idem pour les données du cours
|
// Participants avec historiques
|
||||||
$course = $this->getData(['course', $courseId]);
|
$enrolment = $this->getData(['enrolment', $courseId]);
|
||||||
// Générer un fichier dans le dossier de l'espace
|
// Générer un fichier dans le dossier de l'espace
|
||||||
file_put_contents(self::DATA_DIR . $courseId . '/course.json', json_encode([$courseId => $course], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode([$courseId => $enrolment], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
// Idem pour la catégorie
|
// Idem pour les données du cours
|
||||||
$category = $this->getData(['category', $this->getData(['course', $courseId, 'category'])]);
|
$course = $this->getData(['course', $courseId]);
|
||||||
// Générer un fichier dans le dossier de l'espace
|
// Générer un fichier dans le dossier de l'espace
|
||||||
file_put_contents(self::DATA_DIR . $courseId . '/category.json', json_encode([$this->getData(['course', $courseId, 'category']) => $category], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
file_put_contents(self::DATA_DIR . $courseId . '/course.json', json_encode([$courseId => $course], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
// Idem pour la catégorie
|
||||||
|
$category = $this->getData(['category', $this->getData(['course', $courseId, 'category'])]);
|
||||||
|
// Générer un fichier dans le dossier de l'espace
|
||||||
|
file_put_contents(self::DATA_DIR . $courseId . '/category.json', json_encode([$this->getData(['course', $courseId, 'category']) => $category], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
|
||||||
// Génère une archive ZIP
|
// Génère une archive ZIP
|
||||||
$this->makeZip(self::TEMP_DIR . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip', self::DATA_DIR . $courseId);
|
$this->makeZip(self::TEMP_DIR . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip', self::DATA_DIR . $courseId);
|
||||||
|
|
||||||
if (!is_dir(self::FILE_DIR . 'source/backup')) {
|
|
||||||
mkdir(self::FILE_DIR . 'source/backup');
|
|
||||||
}
|
|
||||||
|
|
||||||
$success = false;
|
|
||||||
$message = helper::translate('Erreur : sauvegarde non générée !');
|
|
||||||
// Transférer dans RFM
|
|
||||||
if (file_exists(self::TEMP_DIR . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip')) {
|
|
||||||
if (!is_dir(self::FILE_DIR . 'source/' . $courseId . '/backup/')) {
|
|
||||||
mkdir(self::FILE_DIR . 'source/' . $courseId . '/backup/');
|
|
||||||
|
|
||||||
|
$success = false;
|
||||||
|
$message = helper::translate('Erreur : sauvegarde non générée !');
|
||||||
|
// Transférer dans RFM
|
||||||
|
if (file_exists(self::TEMP_DIR . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip')) {
|
||||||
|
if (!is_dir(self::FILE_DIR . 'source/' . $courseId )) {
|
||||||
|
mkdir(self::FILE_DIR . 'source/' . $courseId );
|
||||||
|
}
|
||||||
|
if (!is_dir(self::FILE_DIR . 'source/' . $courseId . '/backup/')) {
|
||||||
|
mkdir(self::FILE_DIR . 'source/' . $courseId . '/backup/');
|
||||||
|
}
|
||||||
|
copy(self::TEMP_DIR . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip', self::FILE_DIR . 'source/' . $courseId . '/backup/' . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip');
|
||||||
|
unlink(self::TEMP_DIR . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip');
|
||||||
|
$success = true;
|
||||||
|
$message = helper::translate('Sauvegarde générée avec succès');
|
||||||
}
|
}
|
||||||
copy(self::TEMP_DIR . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip', self::FILE_DIR . 'source/' . $courseId . '/backup/' . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip');
|
|
||||||
unlink(self::TEMP_DIR . $courseId . '-' . date('Y-m-d-H-i-s', time()) . '.zip');
|
// Valeurs en sortie
|
||||||
$success = true;
|
$this->addOutput([
|
||||||
$message = helper::translate('Sauvegarde générée avec succès');
|
'redirect' => helper::baseUrl() . 'course',
|
||||||
|
'state' => $success,
|
||||||
|
'notification' => $message,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sauvegarde d'un cours sans option
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function restore()
|
||||||
|
{
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'redirect' => helper::baseUrl() . 'course',
|
'title' => helper::translate('Restaurer un espace'),
|
||||||
'state' => $success,
|
'view' => 'restore'
|
||||||
'notification' => $message,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
20
core/module/course/view/restore/restore.css
Normal file
20
core/module/course/view/restore/restore.css
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* This file is part of Zwii.
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* @author Rémi Jean <remi.jean@outlook.com>
|
||||||
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
||||||
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
||||||
|
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
||||||
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
||||||
|
* @link http://zwiicms.fr/
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @import url("site/data/admin.css"); */
|
||||||
|
|
||||||
|
/** NE PAS EFFACER
|
||||||
|
* admin.css
|
||||||
|
*/
|
33
core/module/course/view/restore/restore.php
Normal file
33
core/module/course/view/restore/restore.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php echo template::formOpen('courseRestoreForm'); ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col1">
|
||||||
|
<?php echo template::button('courseRestoreBack', [
|
||||||
|
'class' => 'buttonGrey',
|
||||||
|
'href' => helper::baseUrl() . 'course',
|
||||||
|
'value' => template::ico('left')
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
<div class="col2 offset9">
|
||||||
|
<?php echo template::submit('courseRestoreSubmit', [
|
||||||
|
'value' => 'Valider'
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col12">
|
||||||
|
<div class="block">
|
||||||
|
<h4>
|
||||||
|
<?php echo helper::translate('Sélectionner une archive'); ?>
|
||||||
|
</h4>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col10 offset1">
|
||||||
|
<?php echo template::file('courseRestoreCSVFile', [
|
||||||
|
'language' => $this->getData(['course', $this->getUser('id'), 'language']),
|
||||||
|
//'label' => 'Fichier de sauvegarde :'
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php echo template::formClose(); ?>
|
Loading…
Reference in New Issue
Block a user