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

@ -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;

View 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) {
}

View 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"] : "";

View 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;
}
}

View 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);

View 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) {
}