Upgrade LBCAlerte to version 3.3

Add upgrade script
This commit is contained in:
Jimmy Monin
2016-11-26 19:19:16 +01:00
parent a7c054b535
commit 58ffd500e6
89 changed files with 6436 additions and 758 deletions

View File

@ -1,122 +1,49 @@
<?php
if (!$userAuthed->getApiKey()) {
$userAuthed->setApiKey(
sha1(
str_repeat(
uniqid($_SERVER["HTTP_HOST"], true),
rand(10, 100)
)
)
);
$userStorage->save($userAuthed);
}
$params = array(
"notification" => $userAuthed->getOption("notification"),
"unique_ads" => $userAuthed->getOption("unique_ads", false)
"unique_ads" => $userAuthed->getOption("unique_ads", false),
"api_key" => $userAuthed->getApiKey(),
"addresses_mails" => $userAuthed->getOption("addresses_mails"),
);
if (!is_array($params["notification"])) {
$params["notification"] = array();
}
$form_values["notification"] = array_replace_recursive(array(
"freeMobile" => array(
"user" => "",
"key" => "",
),
"notifymyandroid" => array(
"token" => "",
),
"pushbullet" => array(
"token" => "",
),
"ovh" => array(
"account" => "",
"login" => "",
"password" => "",
"from" => "",
"to" => "",
),
"pushover" => array(
"token" => "",
"user_key" => "",
),
), $params["notification"]);
$errors = array();
$errorsTest = array();
require DOCUMENT_ROOT."/app/data/notifications.php";
$form_values = array(
"api_key" => $params["api_key"],
"unique_ads" => $params["unique_ads"],
"addresses_mails" => $params["addresses_mails"],
);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$params = array_merge($params, $_POST);
$form_values = array_intersect_key($_POST, $form_values);
// test config Free Mobile
foreach ($params["notification"] AS $section => $options) {
if (is_array($options)) {
$hasValue = false;
foreach ($options AS $name => $value) {
if (empty($value)) {
$errors["notification"][$section][$name] = "Ce champ doit être renseigné.";
} else {
$hasValue = true;
}
}
if (!$hasValue) {
unset($errors["notification"][$section]);
$params["notification"][$section] = false;
}
}
}
if (empty($errors["notification"])) {
unset($errors["notification"]);
}
if (empty($errors)) {
if (!empty($_POST["testFreeMobile"])) {
$sms = \Message\AdapterFactory::factory("freeMobile", $params["notification"]["freeMobile"]);
try {
$sms->send("La notification SMS est fonctionnelle.");
} catch (Exception $e) {
$errorsTest["freeMobile"] = "Erreur lors de l'envoi du SMS : (".$e->getCode().") ".$e->getMessage();
}
} elseif (!empty($_POST["testPushbullet"])) {
if (empty($_POST["notification"]["pushbullet"]["token"])) {
$errors["notification"]["pushbullet"]["token"] = "Veuillez renseigner la clé d'identification. ";
} else {
$sender = \Message\AdapterFactory::factory("pushbullet", $_POST["notification"]["pushbullet"]);
try {
$sender->send("La notification Pushbullet est fonctionnelle");
} catch (Exception $e) {
$errorsTest["pushbullet"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
}
} elseif (!empty($_POST["testOvh"])) {
$sender = \Message\AdapterFactory::factory("SmsOvh", $params["notification"]["ovh"]);
try {
$sender->send("La notification SMS est fonctionnelle.");
} catch (Exception $e) {
$errorsTest["ovh"] = "Erreur lors de l'envoi du SMS : (".$e->getCode().") ".$e->getMessage();
}
} elseif (!empty($_POST["testNotifyMyAndroid"])) {
if (empty($_POST["notification"]["notifymyandroid"]["token"])) {
$errors["notification"]["notifymyandroid"]["token"] = "Veuillez renseigner la clé d'identification.";
} else {
$sender = \Message\AdapterFactory::factory("notifymyandroid", $_POST["notification"]["notifymyandroid"]);
try {
$sender->send("La notification NotifyMyAndroid est fonctionnelle", array(
"title" => "Test alerte"
));
} catch (Exception $e) {
$errorsTest["notifymyandroid"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
}
} elseif (!empty($_POST["testPushover"])) {
if (empty($_POST["notification"]["pushover"]["token"])) {
$errors["notification"]["pushover"]["token"] = "Veuillez renseigner la clé application.";
} elseif (empty($_POST["notification"]["pushover"]["user_key"])) {
$errors["notification"]["pushover"]["user_key"] = "Veuillez renseigner la clé utilisateur.";
} else {
$sender = \Message\AdapterFactory::factory("pushover", $_POST["notification"]["pushover"]);
try {
$sender->send("La notification Pushover est fonctionnelle");
} catch (Exception $e) {
$errorsTest["pushover"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
}
} else {
$userAuthed->mergeOptions($params);
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings"); exit;
}
if (!empty($_POST["regenerate-apikey"])) {
$userAuthed->setApiKey(
sha1(
str_repeat(
uniqid($_SERVER["HTTP_HOST"], true),
rand(10, 100)
)
)
);
}
$userAuthed->mergeOptions($form_values);
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings"); exit;
}
$userSettingsSaved = isset($_SESSION["userSettingsSaved"]) && true === $_SESSION["userSettingsSaved"];