🔨 Sauvegarde les suppressions et supprime les créations
This commit is contained in:
parent
852e9ba1c5
commit
0353fe68cc
24
cron.php
24
cron.php
@ -28,12 +28,21 @@ function copy_folder($from, $to)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete_folder($folder) {
|
||||||
|
$files = array_diff(scandir($folder), ['.','..']);
|
||||||
|
foreach ($files as $file) {
|
||||||
|
(is_dir(sprintf('%s/%s', $folder, $file))) ? delete_folder(sprintf('%s/%s', $folder, $file)) : unlink(sprintf('%s/%s', $folder, $file));
|
||||||
|
}
|
||||||
|
return rmdir($folder);
|
||||||
|
}
|
||||||
|
|
||||||
echo sprintf('%u annonces locales, normalement en ligne.%s', count($existing_deals), "\n");
|
echo sprintf('%u annonces locales, normalement en ligne.%s', count($existing_deals), "\n");
|
||||||
$script_params = parse_ini_file(sprintf('%s/lbcreposter.ini', DEALS_DIR), true);
|
$script_params = parse_ini_file(sprintf('%s/lbcreposter.ini', DEALS_DIR), true);
|
||||||
$config = new \Shikiryu\LBCReposter\Config($script_params);
|
$config = new \Shikiryu\LBCReposter\Config($script_params);
|
||||||
$account = new \Shikiryu\LBCReposter\Account($config);
|
$account = new \Shikiryu\LBCReposter\Account($config);
|
||||||
$actions = new \Shikiryu\LBCReposter\Actions($account);
|
$actions = new \Shikiryu\LBCReposter\Actions($account);
|
||||||
$actions->setDebug(LOGS_DIR);
|
$actions->setDebug(LOGS_DIR);
|
||||||
|
$deals_to_backup = $existing_deals;
|
||||||
|
|
||||||
if ($actions->connect()) {
|
if ($actions->connect()) {
|
||||||
// existing deals
|
// existing deals
|
||||||
@ -61,6 +70,7 @@ if ($actions->connect()) {
|
|||||||
// sinon on la laisse
|
// sinon on la laisse
|
||||||
echo sprintf('et tout va bien. %s', "\n");
|
echo sprintf('et tout va bien. %s', "\n");
|
||||||
}
|
}
|
||||||
|
unset($deals_to_backup[$deal->getId()]);
|
||||||
} else {
|
} else {
|
||||||
echo sprintf('L\'annonce %s n\'existait pas et est sauvegardée. %s', $deal->getSubject(), "\n");
|
echo sprintf('L\'annonce %s n\'existait pas et est sauvegardée. %s', $deal->getSubject(), "\n");
|
||||||
// Une annonce non sauvegardée ? on la sauve
|
// Une annonce non sauvegardée ? on la sauve
|
||||||
@ -68,15 +78,21 @@ if ($actions->connect()) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup
|
||||||
|
foreach ($deals_to_backup as $deal_to_backup) {
|
||||||
|
rename(EXISTING_DEALS_DIR.'/'.$deal_to_backup->getId(), BACKUP_DEALS_DIR.'/'.$deal_to_backup->getId());
|
||||||
|
}
|
||||||
|
|
||||||
// Creation
|
// Creation
|
||||||
foreach (new DirectoryIterator(NEW_DEALS_DIR) as $new_deal) {
|
foreach (new DirectoryIterator(NEW_DEALS_DIR) as $new_deal) {
|
||||||
if ($new_deal->isDir() && !$new_deal->isDot()) {
|
if ($new_deal->isDir() && !$new_deal->isDot()) {
|
||||||
$new_deal = \Shikiryu\LBCReposter\Deal::fromJSON($new_deal->getRealPath() . '/data.json');
|
$deal_to_create = \Shikiryu\LBCReposter\Deal::fromJSON($new_deal->getRealPath() . '/data.json');
|
||||||
if ($actions->create($new_deal)) {
|
if ($actions->create($deal_to_create)) {
|
||||||
echo sprintf('L\'annonce %s a bien été créée. %s', $new_deal->getSubject(), "\n");
|
delete_folder($new_deal->getRealPath());
|
||||||
|
echo sprintf('L\'annonce %s a bien été créée. %s', $deal_to_create->getSubject(), "\n");
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
echo sprintf('L\'annonce %s n\'a pas bien été créée. %s', $new_deal->getSubject(), "\n");
|
echo sprintf('L\'annonce %s n\'a pas bien été créée. %s', $deal_to_create->getSubject(), "\n");
|
||||||
}
|
}
|
||||||
sleep(30);
|
sleep(30);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user