mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-26 13:17:34 +02:00
Upgrade LBCAlerte to version 3.3
Add upgrade script
This commit is contained in:
40
sources/app/annonce/scripts/backup.php
Normal file
40
sources/app/annonce/scripts/backup.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
$url = !empty($_GET["aurl"]) ? $_GET["aurl"] : null;
|
||||
|
||||
$logger = Logger::getLogger("main");
|
||||
|
||||
$content = $client->request($url);
|
||||
|
||||
try {
|
||||
$parser = \AdService\ParserFactory::factory($url);
|
||||
} catch (\AdService\Exception $e) {
|
||||
$logger->err($e->getMessage());
|
||||
}
|
||||
|
||||
$ad = $parser->processAd(
|
||||
$content,
|
||||
parse_url($url, PHP_URL_SCHEME)
|
||||
);
|
||||
|
||||
$ad_stored = $storage->fetchById($ad->getId());
|
||||
if ($ad_stored) {
|
||||
if ($_SERVER["REQUEST_METHOD"] != "POST") {
|
||||
return;
|
||||
}
|
||||
|
||||
// Supprime les photos
|
||||
$adPhoto->delete($ad);
|
||||
}
|
||||
|
||||
|
||||
if (!$ad_stored) {
|
||||
$ad_stored = new \App\Ad\Ad();
|
||||
}
|
||||
|
||||
$ad_stored->setFromArray($ad->toArray());
|
||||
$storage->save($ad_stored);
|
||||
|
||||
$adPhoto->import($ad_stored);
|
||||
|
||||
header("LOCATION: ./?mod=annonce&a=view&id=".$ad->getId()); exit;
|
27
sources/app/annonce/scripts/form-comment.php
Normal file
27
sources/app/annonce/scripts/form-comment.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use AdService\SiteConfigFactory;
|
||||
|
||||
if (!isset($_GET["id"])) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
$ad = $storage->fetchById($_GET["id"]);
|
||||
if (!$ad) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$comment = isset($_POST["comment"]) ? trim($_POST["comment"]) : "";
|
||||
$ad->setComment($comment);
|
||||
$storage->save($ad);
|
||||
|
||||
header("LOCATION: ./?mod=annonce&a=view&id=".$ad->getId()."&update=1");
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$ad_config = SiteConfigFactory::factory($ad->getLink());
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
17
sources/app/annonce/scripts/form-delete.php
Normal file
17
sources/app/annonce/scripts/form-delete.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
if (!isset($_GET["id"])) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
$ad = $storage->fetchById($_GET["id"]);
|
||||
if (!$ad) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
if (isset($_POST["id"]) && $_POST["id"] == $_GET["id"]) {
|
||||
$storage->delete($ad);
|
||||
$adPhoto->delete($ad);
|
||||
}
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
$referer = isset($_GET["r"]) ? $_GET["r"] : "";
|
46
sources/app/annonce/scripts/form.php
Normal file
46
sources/app/annonce/scripts/form.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
$ad = new App\Ad\Ad();
|
||||
|
||||
$link = "";
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
if (empty($_POST["link"])) {
|
||||
$errors["link"] = "Ce champ est obligatoire.";
|
||||
} else {
|
||||
$link = $_POST["link"];
|
||||
try {
|
||||
$siteConfig = \AdService\SiteConfigFactory::factory($link);
|
||||
$parser = \AdService\ParserFactory::factory($link);
|
||||
} catch (\Exception $e) {
|
||||
$errors["link"] = "Cette adresse ne semble pas valide.";
|
||||
}
|
||||
}
|
||||
if (empty($errors)) {
|
||||
$ad = $parser->processAd(
|
||||
$client->request($link),
|
||||
parse_url($link, PHP_URL_SCHEME)
|
||||
);
|
||||
if (!$ad) {
|
||||
$errors["link"] = "Impossible de sauvegarder l'annonce (annonce hors ligne ou format des données invalides).";
|
||||
}
|
||||
}
|
||||
if (empty($errors) && !empty($ad)) {
|
||||
$ad = $parser->processAd(
|
||||
$client->request($link),
|
||||
parse_url($link, PHP_URL_SCHEME)
|
||||
);
|
||||
|
||||
$ad_stored = $storage->fetchById($ad->getId());
|
||||
if (!$ad_stored) {
|
||||
$ad_stored = new \App\Ad\Ad();
|
||||
}
|
||||
|
||||
$ad_stored->setFromArray($ad->toArray());
|
||||
$storage->save($ad_stored);
|
||||
|
||||
$adPhoto->import($ad_stored);
|
||||
|
||||
header("LOCATION: ./?mod=annonce");
|
||||
exit;
|
||||
}
|
||||
}
|
28
sources/app/annonce/scripts/index.php
Normal file
28
sources/app/annonce/scripts/index.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
if (isset($_GET["sort"])) {
|
||||
if (in_array($_GET["sort"], array("title", "price", "city", "category", "author", "date", "zip_code", "date_created"))) {
|
||||
if (!isset($_SESSION["backupad"]["sort"]) || $_SESSION["backupad"]["sort"] != $_GET["sort"]) {
|
||||
$_SESSION["backupad"]["sort"] = $_GET["sort"];
|
||||
$_SESSION["backupad"]["order"] = "asc";
|
||||
} elseif (!isset($_SESSION["backupad"]["order"]) || $_SESSION["backupad"]["order"] == "desc") {
|
||||
$_SESSION["backupad"]["order"] = "asc";
|
||||
} else {
|
||||
$_SESSION["backupad"]["order"] = "desc";
|
||||
}
|
||||
}
|
||||
header("LOCATION: ?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
$sort = "date_created";
|
||||
$order = "desc";
|
||||
if (isset($_SESSION["backupad"]["sort"])) {
|
||||
$sort = $_SESSION["backupad"]["sort"];
|
||||
}
|
||||
if (isset($_SESSION["backupad"]["order"])) {
|
||||
$order = $_SESSION["backupad"]["order"];
|
||||
}
|
||||
|
||||
$ads = $storage->fetchAll($sort." ".$order);
|
||||
|
||||
|
18
sources/app/annonce/scripts/view.php
Normal file
18
sources/app/annonce/scripts/view.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use AdService\SiteConfigFactory;
|
||||
|
||||
if (!isset($_GET["id"])) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
$ad = $storage->fetchById($_GET["id"]);
|
||||
if (!$ad) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$ad_config = SiteConfigFactory::factory($ad->getLink());
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
Reference in New Issue
Block a user