2018-04-02 08:29:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2021-02-17 13:49:58 +01:00
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2023-01-09 10:23:32 +01:00
|
|
|
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
2022-12-29 17:02:20 +01:00
|
|
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
2020-09-01 20:48:40 +02:00
|
|
|
* @link http://zwiicms.fr/
|
2018-04-02 08:29:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
class install extends common
|
|
|
|
{
|
2018-04-02 08:29:19 +02:00
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
'index' => self::GROUP_VISITOR,
|
2022-09-21 15:09:25 +02:00
|
|
|
"postinstall" => self::GROUP_VISITOR,
|
2018-04-02 08:29:19 +02:00
|
|
|
'steps' => self::GROUP_ADMIN,
|
2020-10-25 22:49:28 +01:00
|
|
|
'update' => self::GROUP_ADMIN
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
|
|
|
|
2022-08-22 21:01:01 +02:00
|
|
|
// Type de proxy
|
|
|
|
public static $proxyType = [
|
|
|
|
'tcp://' => 'TCP',
|
|
|
|
'http://' => 'HTTP'
|
|
|
|
];
|
|
|
|
|
2021-10-19 19:14:52 +02:00
|
|
|
// Thèmes proposés à l'installation
|
2023-02-07 13:31:11 +01:00
|
|
|
public static $themes = [];
|
2019-05-02 13:21:48 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $newVersion;
|
|
|
|
|
2022-11-24 09:03:29 +01:00
|
|
|
// Fichiers des Interface
|
2022-09-21 19:51:46 +02:00
|
|
|
public static $i18nFiles = [];
|
2022-09-21 16:02:06 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
2022-09-21 15:09:25 +02:00
|
|
|
* Pré-installation - choix de la langue
|
2018-04-02 08:29:19 +02:00
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function index()
|
|
|
|
{
|
2022-09-21 15:09:25 +02:00
|
|
|
// Accès refusé
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['user']) !== []) {
|
2022-09-21 15:09:25 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Accès autorisé
|
2023-02-21 15:16:41 +01:00
|
|
|
// Soumission du formulaire
|
|
|
|
if ($this->isPost()) {
|
|
|
|
$lang = $this->getInput('installLanguage');
|
2023-04-12 21:38:12 +02:00
|
|
|
// Pour la suite de l'installation
|
|
|
|
// setcookie('ZWII_UI', $lang, time() + 3600, helper::baseUrl(false, false), '', false, false);
|
|
|
|
$_SESSION['ZWII_UI'] = $this->getInput('installLanguage');
|
2023-02-21 15:16:41 +01:00
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-04-12 21:54:07 +02:00
|
|
|
'redirect' => helper::baseUrl() . 'install/postinstall'
|
2023-02-21 15:16:41 +01:00
|
|
|
]);
|
2022-09-21 15:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Liste des langues UI disponibles
|
|
|
|
if (is_dir(self::I18N_DIR)) {
|
2023-02-20 11:29:21 +01:00
|
|
|
foreach ($this->getData(['languages']) as $lang => $value) {
|
2023-02-20 15:22:58 +01:00
|
|
|
self::$i18nFiles[$lang] = self::$languages[$lang];
|
|
|
|
;
|
2022-09-21 15:09:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
2022-10-02 10:59:42 +02:00
|
|
|
'title' => helper::translate('Installation'),
|
2022-09-21 15:09:25 +02:00
|
|
|
'view' => 'index'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* post Installation
|
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function postInstall()
|
|
|
|
{
|
2018-04-02 08:29:19 +02:00
|
|
|
// Accès refusé
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['user']) !== []) {
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-06-02 18:49:24 +02:00
|
|
|
'access' => false
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Accès autorisé
|
|
|
|
else {
|
|
|
|
// Soumission du formulaire
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->isPost()) {
|
2022-10-05 06:50:56 +02:00
|
|
|
|
2020-09-09 17:21:02 +02:00
|
|
|
$success = true;
|
2022-10-27 21:22:06 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
// Double vérification pour le mot de passe
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getInput('installPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('installConfirmPassword', helper::FILTER_STRING_SHORT, true)) {
|
2018-04-02 08:29:19 +02:00
|
|
|
self::$inputNotices['installConfirmPassword'] = 'Incorrect';
|
2020-09-09 17:21:02 +02:00
|
|
|
$success = false;
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2020-09-09 17:21:02 +02:00
|
|
|
// Utilisateur
|
2018-04-02 08:29:19 +02:00
|
|
|
$userFirstname = $this->getInput('installFirstname', helper::FILTER_STRING_SHORT, true);
|
|
|
|
$userLastname = $this->getInput('installLastname', helper::FILTER_STRING_SHORT, true);
|
|
|
|
$userMail = $this->getInput('installMail', helper::FILTER_MAIL, true);
|
|
|
|
$userId = $this->getInput('installId', helper::FILTER_ID, true);
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2020-09-08 21:25:42 +02:00
|
|
|
// Création de l'utilisateur si les données sont complétées.
|
2020-09-24 10:23:57 +02:00
|
|
|
// success retour de l'enregistrement des données
|
|
|
|
$success = $this->setData([
|
|
|
|
'user',
|
|
|
|
$userId,
|
|
|
|
[
|
|
|
|
'firstname' => $userFirstname,
|
|
|
|
'forgot' => 0,
|
|
|
|
'group' => self::GROUP_ADMIN,
|
|
|
|
'lastname' => $userLastname,
|
2020-10-31 17:55:54 +01:00
|
|
|
'pseudo' => 'Admin',
|
|
|
|
'signature' => 1,
|
2020-09-24 10:23:57 +02:00
|
|
|
'mail' => $userMail,
|
2022-10-26 15:53:26 +02:00
|
|
|
'password' => $this->getInput('installPassword', helper::FILTER_PASSWORD, true),
|
2023-02-20 15:22:58 +01:00
|
|
|
'language' => self::$i18nUI
|
2020-09-24 10:23:57 +02:00
|
|
|
]
|
|
|
|
]);
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2020-09-09 17:21:02 +02:00
|
|
|
// Compte créé, envoi du mail et création des données du site
|
|
|
|
if ($success) { // Formulaire complété envoi du mail
|
2022-09-29 08:45:59 +02:00
|
|
|
// Envoie le mail
|
|
|
|
// Sent contient true si réussite sinon code erreur d'envoi en clair
|
|
|
|
$sent = $this->sendMail(
|
|
|
|
$userMail,
|
|
|
|
'Installation de votre site',
|
|
|
|
'Bonjour' . ' <strong>' . $userFirstname . ' ' . $userLastname . '</strong>,<br><br>' .
|
2023-02-07 13:31:11 +01:00
|
|
|
'Voici les détails de votre installation.<br><br>' .
|
|
|
|
'<strong>URL du site :</strong> <a href="' . helper::baseUrl(false) . '" target="_blank">' . helper::baseUrl(false) . '</a><br>' .
|
|
|
|
'<strong>Identifiant du compte :</strong> ' . $this->getInput('installId') . '<br>',
|
2023-02-23 16:02:06 +01:00
|
|
|
null,
|
|
|
|
$this->getData(['config', 'smtp', 'from']),
|
2022-09-29 08:45:59 +02:00
|
|
|
);
|
2022-09-21 19:51:46 +02:00
|
|
|
|
2023-04-21 17:25:08 +02:00
|
|
|
// Validation de la langue transmise
|
|
|
|
self::$i18nUI = $_SESSION['ZWII_UI'];
|
|
|
|
self::$i18nUI = array_key_exists(self::$i18nUI, self::$languages) ? self::$i18nUI : 'fr_FR';
|
|
|
|
|
|
|
|
// par défaut le contenu est la langue d'installation
|
|
|
|
self::$i18nContent = self::$i18nUI;
|
|
|
|
$_SESSION['ZWII_CONTENT'] = self::$i18nContent;
|
|
|
|
|
|
|
|
// Création du dossier de langue avec le marqueur de langue par défaut
|
|
|
|
if (!is_dir(self::DATA_DIR . self::$i18nContent)) {
|
|
|
|
mkdir(self::DATA_DIR . self::$i18nContent);
|
2023-04-21 17:25:24 +02:00
|
|
|
touch(self::DATA_DIR . self::$i18nContent . '/.default');
|
2023-04-21 17:25:08 +02:00
|
|
|
}
|
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
// Installation du site de test
|
2022-12-28 16:35:20 +01:00
|
|
|
if (
|
|
|
|
$this->getInput('installDefaultData', helper::FILTER_BOOLEAN) === false
|
2023-02-20 15:22:58 +01:00
|
|
|
&& self::$i18nContent === 'fr_FR'
|
2022-12-28 16:35:20 +01:00
|
|
|
) {
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->initData('page', self::$i18nContent, true);
|
|
|
|
$this->initData('module', self::$i18nContent, true);
|
|
|
|
$this->setData(['module', 'blog', 'posts', 'mon-premier-article', 'userId', $userId]);
|
|
|
|
$this->setData(['module', 'blog', 'posts', 'mon-deuxieme-article', 'userId', $userId]);
|
|
|
|
$this->setData(['module', 'blog', 'posts', 'mon-troisieme-article', 'userId', $userId]);
|
2022-12-18 11:34:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Jeu réduit pour les pages étrangères
|
2023-02-20 15:22:58 +01:00
|
|
|
if (self::$i18nContent !== 'fr_FR') {
|
2022-12-18 11:34:06 +01:00
|
|
|
$this->initData('page', self::$i18nContent, false);
|
|
|
|
$this->initData('module', self::$i18nContent, false);
|
2023-02-20 15:22:58 +01:00
|
|
|
// Supprime l'installation FR générée par défaut.
|
2023-04-12 21:38:12 +02:00
|
|
|
if (is_dir(self::DATA_DIR . 'fr_FR'))
|
|
|
|
$this->removeDir(self::DATA_DIR . 'fr_FR');
|
2022-09-29 08:45:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sauvegarder la configuration du Proxy
|
|
|
|
$this->setData(['config', 'proxyType', $this->getInput('installProxyType')]);
|
|
|
|
$this->setData(['config', 'proxyUrl', $this->getInput('installProxyUrl')]);
|
|
|
|
$this->setData(['config', 'proxyPort', $this->getInput('installProxyPort', helper::FILTER_INT)]);
|
|
|
|
|
|
|
|
// Images exemples livrées dans tous les cas
|
|
|
|
try {
|
|
|
|
// Décompression dans le dossier de fichier temporaires
|
|
|
|
if (file_exists(self::TEMP_DIR . 'files.tar.gz')) {
|
|
|
|
unlink(self::TEMP_DIR . 'files.tar.gz');
|
|
|
|
}
|
|
|
|
if (file_exists(self::TEMP_DIR . 'files.tar')) {
|
|
|
|
unlink(self::TEMP_DIR . 'files.tar');
|
|
|
|
}
|
|
|
|
copy('core/module/install/ressource/files.tar.gz', self::TEMP_DIR . 'files.tar.gz');
|
|
|
|
$pharData = new PharData(self::TEMP_DIR . 'files.tar.gz');
|
|
|
|
$pharData->decompress();
|
|
|
|
// Installation
|
|
|
|
$pharData->extractTo(__DIR__ . '/../../../', null, true);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$success = $e->getMessage();
|
|
|
|
}
|
2022-10-16 07:41:57 +02:00
|
|
|
|
|
|
|
// Nettoyage
|
2022-09-29 08:45:59 +02:00
|
|
|
unlink(self::TEMP_DIR . 'files.tar.gz');
|
|
|
|
unlink(self::TEMP_DIR . 'files.tar');
|
2023-01-01 11:12:30 +01:00
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
// Créer le dossier des fontes
|
|
|
|
if (!is_dir(self::DATA_DIR . 'fonts')) {
|
|
|
|
mkdir(self::DATA_DIR . 'fonts');
|
2021-06-01 09:19:48 +02:00
|
|
|
}
|
2022-04-16 10:08:59 +02:00
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
// Installation du thème sélectionné
|
2023-02-23 22:14:26 +01:00
|
|
|
$dataThemes = json_decode(file_get_contents('core/module/install/ressource/themes/themes.json'), true);
|
|
|
|
$dataThemes = $dataThemes['themes'];
|
2023-02-27 14:33:03 +01:00
|
|
|
$themeFilename = $dataThemes[$this->getInput('installTheme', helper::FILTER_STRING_SHORT)]['filename'];
|
|
|
|
if ($themeFilename !== '') {
|
2021-10-19 19:14:52 +02:00
|
|
|
$theme = new theme;
|
2023-02-27 14:33:03 +01:00
|
|
|
$theme->import('core/module/install/ressource/themes/' . $themeFilename);
|
2022-09-29 08:45:59 +02:00
|
|
|
}
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
// Copie des thèmes dans les fichiers
|
|
|
|
if (!is_dir(self::FILE_DIR . 'source/theme')) {
|
|
|
|
mkdir(self::FILE_DIR . 'source/theme');
|
|
|
|
}
|
|
|
|
$this->copyDir('core/module/install/ressource/themes', self::FILE_DIR . 'source/theme');
|
|
|
|
unlink(self::FILE_DIR . 'source/theme/themes.json');
|
|
|
|
|
2022-12-28 16:35:20 +01:00
|
|
|
// Copie des langues de l'UI et génération de la base de données
|
|
|
|
if (is_dir(self::I18N_DIR) === false) {
|
|
|
|
mkdir(self::I18N_DIR);
|
|
|
|
}
|
2023-01-01 11:12:30 +01:00
|
|
|
|
|
|
|
// Créer la base de données des langues
|
|
|
|
copy('core/module/install/ressource/i18n/languages.json', self::DATA_DIR . 'languages.json');
|
2022-12-28 16:35:20 +01:00
|
|
|
$this->copyDir('core/module/install/ressource/i18n', self::I18N_DIR);
|
2022-12-30 09:15:59 +01:00
|
|
|
unlink(self::I18N_DIR . 'languages.json');
|
2022-12-28 16:35:20 +01:00
|
|
|
|
2023-02-23 22:00:51 +01:00
|
|
|
// Fixe l'adresse from pour les envois d'email
|
|
|
|
$this->setData(['config', 'smtp', 'from', 'no-reply@' . str_replace('www.', '', $_SERVER['HTTP_HOST'])]);
|
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-02-20 15:22:58 +01:00
|
|
|
'redirect' => helper::baseUrl(true) . $this->getData(['locale', 'homePageId']),
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => $sent === true ? helper::translate('Installation terminée') : $sent,
|
2023-02-07 13:31:11 +01:00
|
|
|
'state' => ($sent === true && $success === true) ? true : null
|
2022-09-29 08:45:59 +02:00
|
|
|
]);
|
2019-12-10 10:53:31 +01:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2022-09-21 19:51:46 +02:00
|
|
|
|
|
|
|
// Affichage du formulaire
|
|
|
|
|
2021-10-19 19:14:52 +02:00
|
|
|
// Récupération de la liste des thèmes
|
2023-02-23 22:00:51 +01:00
|
|
|
$dataThemes = json_decode(file_get_contents('core/module/install/ressource/themes/themes.json'), true);
|
|
|
|
$dataThemes = $dataThemes['themes'];
|
2022-04-06 09:46:28 +02:00
|
|
|
self::$themes = helper::arrayColumn($dataThemes, 'name');
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
2022-10-02 10:59:42 +02:00
|
|
|
'title' => helper::translate('Installation'),
|
2022-09-21 15:09:25 +02:00
|
|
|
'view' => 'postinstall'
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Étapes de mise à jour
|
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function steps()
|
|
|
|
{
|
|
|
|
switch ($this->getInput('step', helper::FILTER_INT)) {
|
2023-02-07 13:31:11 +01:00
|
|
|
// Préparation
|
2018-04-02 08:29:19 +02:00
|
|
|
case 1:
|
|
|
|
$success = true;
|
2023-03-16 15:56:19 +01:00
|
|
|
$message = '';
|
2020-06-01 08:19:34 +02:00
|
|
|
// RAZ la mise à jour auto
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->setData(['core', 'updateAvailable', false]);
|
2020-02-18 11:18:27 +01:00
|
|
|
// Backup du dossier Data
|
2022-09-29 08:45:59 +02:00
|
|
|
helper::autoBackup(self::BACKUP_DIR, ['backup', 'tmp', 'file']);
|
2020-06-14 10:36:36 +02:00
|
|
|
// Sauvegarde htaccess
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['config', 'autoUpdateHtaccess'])) {
|
2020-06-14 10:36:36 +02:00
|
|
|
$success = copy('.htaccess', '.htaccess' . '.bak');
|
2023-03-16 15:56:19 +01:00
|
|
|
$message = 'Erreur de copie du fichier htaccess';
|
2020-06-14 10:36:36 +02:00
|
|
|
}
|
2020-02-18 11:18:27 +01:00
|
|
|
// Nettoyage des fichiers d'installation précédents
|
2022-09-29 08:45:59 +02:00
|
|
|
if (file_exists(self::TEMP_DIR . 'update.tar.gz') && $success) {
|
2023-03-14 13:11:02 +01:00
|
|
|
$success = $success || unlink(self::TEMP_DIR . 'update.tar.gz');
|
2023-03-17 08:48:54 +01:00
|
|
|
$message = 'Impossible d\'effacer la mise à jour précédente';
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if (file_exists(self::TEMP_DIR . 'update.tar') && $success) {
|
2023-03-14 13:11:02 +01:00
|
|
|
$success = $success || unlink(self::TEMP_DIR . 'update.tar');
|
2023-03-17 08:48:54 +01:00
|
|
|
$message = 'Impossible d\'effacer la mise à jour précédente';
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
2023-03-21 15:48:42 +01:00
|
|
|
'data' => $success ? null : json_encode($message, JSON_UNESCAPED_UNICODE)
|
2018-04-02 08:29:19 +02:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
2023-02-07 13:31:11 +01:00
|
|
|
// Téléchargement
|
2018-04-02 08:29:19 +02:00
|
|
|
case 2:
|
2022-09-29 08:45:59 +02:00
|
|
|
file_put_contents(self::TEMP_DIR . 'update.tar.gz', helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/update.tar.gz'));
|
2022-02-10 14:43:00 +01:00
|
|
|
$md5origin = helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/update.md5');
|
2023-03-16 15:13:52 +01:00
|
|
|
$md5origin = explode(' ', $md5origin);
|
2022-09-29 08:45:59 +02:00
|
|
|
$md5target = md5_file(self::TEMP_DIR . 'update.tar.gz');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
2022-01-09 11:33:41 +01:00
|
|
|
'success' => $md5origin[0] === $md5target,
|
2023-03-21 15:48:42 +01:00
|
|
|
'data' => $md5origin[0] === $md5target ? null : json_encode('Erreur de téléchargement ou de somme de contrôle', JSON_UNESCAPED_UNICODE)
|
2018-04-02 08:29:19 +02:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
2023-02-07 13:31:11 +01:00
|
|
|
// Installation
|
2018-04-02 08:29:19 +02:00
|
|
|
case 3:
|
|
|
|
$success = true;
|
|
|
|
// Check la réécriture d'URL avant d'écraser les fichiers
|
|
|
|
$rewrite = helper::checkRewrite();
|
|
|
|
// Décompression et installation
|
|
|
|
try {
|
|
|
|
// Décompression dans le dossier de fichier temporaires
|
2022-09-29 08:45:59 +02:00
|
|
|
$pharData = new PharData(self::TEMP_DIR . 'update.tar.gz');
|
2018-04-02 08:29:19 +02:00
|
|
|
$pharData->decompress();
|
|
|
|
// Installation
|
|
|
|
$pharData->extractTo(__DIR__ . '/../../../', null, true);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$success = $e->getMessage();
|
|
|
|
}
|
2020-06-02 18:49:24 +02:00
|
|
|
// Nettoyage du dossier
|
2022-09-29 08:45:59 +02:00
|
|
|
if (file_exists(self::TEMP_DIR . 'update.tar.gz')) {
|
|
|
|
unlink(self::TEMP_DIR . 'update.tar.gz');
|
2019-05-19 21:21:36 +02:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if (file_exists(self::TEMP_DIR . 'update.tar')) {
|
|
|
|
unlink(self::TEMP_DIR . 'update.tar');
|
2019-05-19 21:21:36 +02:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
|
|
|
'data' => $rewrite
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
2023-02-07 13:31:11 +01:00
|
|
|
// Configuration
|
2018-04-02 08:29:19 +02:00
|
|
|
case 4:
|
|
|
|
$success = true;
|
2023-04-11 07:13:33 +02:00
|
|
|
$message = '';
|
2019-06-04 20:29:42 +02:00
|
|
|
$rewrite = $this->getInput('data');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Réécriture d'URL
|
2023-04-11 07:13:33 +02:00
|
|
|
if ($rewrite === 'true') { // Ajout des lignes dans le .htaccess
|
2022-04-28 11:04:01 +02:00
|
|
|
$fileContent = file_get_contents('.htaccess');
|
2023-02-07 13:31:11 +01:00
|
|
|
$rewriteData = PHP_EOL .
|
|
|
|
'# URL rewriting' . PHP_EOL .
|
2022-09-29 08:45:59 +02:00
|
|
|
'<IfModule mod_rewrite.c>' . PHP_EOL .
|
|
|
|
"\tRewriteEngine on" . PHP_EOL .
|
|
|
|
"\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL .
|
|
|
|
"\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL .
|
|
|
|
"\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL .
|
|
|
|
"\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL .
|
|
|
|
'</IfModule>' . PHP_EOL .
|
|
|
|
'# URL rewriting' . PHP_EOL;
|
2022-04-28 11:04:01 +02:00
|
|
|
$fileContent = str_replace('# URL rewriting', $rewriteData, $fileContent);
|
2023-03-14 13:11:02 +01:00
|
|
|
$r = file_put_contents(
|
2018-04-02 08:29:19 +02:00
|
|
|
'.htaccess',
|
2022-04-28 11:04:01 +02:00
|
|
|
$fileContent
|
|
|
|
);
|
2023-03-14 13:11:02 +01:00
|
|
|
$success = $r === false ? false : true;
|
2023-03-17 08:44:19 +01:00
|
|
|
$message = $r === false ? 'Le fichier htaccess n\'a pas été restauré' : null;
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2020-06-14 10:36:36 +02:00
|
|
|
// Recopie htaccess
|
2022-09-29 08:45:59 +02:00
|
|
|
if (
|
|
|
|
$this->getData(['config', 'autoUpdateHtaccess']) &&
|
|
|
|
$success && file_exists('.htaccess.bak')
|
2020-06-14 10:36:36 +02:00
|
|
|
) {
|
2022-09-29 08:45:59 +02:00
|
|
|
// L'écraser avec le backup
|
2023-03-14 13:11:02 +01:00
|
|
|
$success = $success || copy('.htaccess.bak', '.htaccess');
|
2022-09-29 08:45:59 +02:00
|
|
|
// Effacer le backup
|
|
|
|
unlink('.htaccess.bak');
|
2020-06-14 10:36:36 +02:00
|
|
|
}
|
2023-02-07 13:31:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Met à jour les dictionnaires des langues depuis les modèles installés
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Langues installées
|
|
|
|
$installedUI = $this->getData(['languages']);
|
|
|
|
|
|
|
|
// Langues disponibles avec la mise à jour
|
2023-02-18 08:57:08 +01:00
|
|
|
$store = json_decode(file_get_contents('core/module/install/ressource/i18n/languages.json'), true);
|
2023-02-07 13:31:11 +01:00
|
|
|
$store = $store['languages'];
|
|
|
|
|
|
|
|
foreach ($installedUI as $key => $value) {
|
|
|
|
if ($store[$key]['version'] > $value['version']) {
|
|
|
|
$this->setData(['languages', $key, $store[$key]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
2023-03-21 15:48:42 +01:00
|
|
|
'data' => json_encode($message, JSON_UNESCAPED_UNICODE)
|
2018-04-02 08:29:19 +02:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mise à jour
|
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function update()
|
|
|
|
{
|
2018-04-02 08:29:19 +02:00
|
|
|
// Nouvelle version
|
2022-02-10 14:43:00 +01:00
|
|
|
self::$newVersion = helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/version');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
2022-10-02 10:59:42 +02:00
|
|
|
'title' => helper::translate('Mise à jour'),
|
2018-04-02 08:29:19 +02:00
|
|
|
'view' => 'update'
|
|
|
|
]);
|
|
|
|
}
|
2023-01-01 11:12:30 +01:00
|
|
|
|
2023-02-07 13:31:11 +01:00
|
|
|
}
|