Skip to content
Code-Schnipsel Gruppen Projekte
Commit d5ecbba3 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

release cron

Übergeordneter 9e1c761c
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -16,4 +16,11 @@
The purge function removes stale data from the cache backends while leaving current data intact
</description>
</cron>
<cron exec="\QUI\Cron\QuiqqerCrons::realeaseDate">
<title>Seiten Veröffentlichung</title>
<description>
Durchsucht das Projekt und aktiviert oder deaktiviert Seiten je nach Veröffentlichungsdatum.
</description>
</cron>
</crons>
\ No newline at end of file
......@@ -207,12 +207,26 @@ class Manager
$cronData = $this->getCronById( $cronId );
$params = array();
if ( !$cronData ) {
throw new \QUI\Exception( 'Cron ID not exist' );
}
call_user_func_array( $cronData['exec'], array($this) );
if ( isset( $cronData['params'] ) )
{
$cronDataParams = json_decode( $cronData['params'], true );
foreach ( $cronDataParams as $entry ) {
$params[ $entry['name'] ] = $entry['value'];
}
if ( !is_array( $params ) ) {
$params = array();
}
}
call_user_func_array( $cronData['exec'], array($params, $this) );
\QUI::getMessagesHandler()->addSuccess(
\QUI::getLocale()->get(
......
......@@ -38,4 +38,111 @@ class QuiqqerCrons
{
\QUI\Cache\Manager::purge();
}
/**
*
* @param Array $params - Cron Parameter
* @param \QUI\Cron\Manager $CronManager
*/
static function realeaseDate($params, $CronManager)
{
if ( !isset( $params['project'] ) ) {
throw new \QUI\Exception( 'Need a project parameter to search release dates' );
}
if ( !isset( $params['lang'] ) ) {
throw new \QUI\Exception( 'Need a lang parameter to search release dates' );
}
$Project = \QUI::getProject( $params['project'], $params['lang'] );
$now = date('Y-m-d H:i:s');
// search sites with release dates
$PDO = \QUI::getDataBase()->getPDO();
$deactivate = array();
$activate = array();
/**
* deactivate sites
*/
$Statment = $PDO->prepare("
SELECT id
FROM {$Project->getAttribute('db_table')}
WHERE active = 1 AND
release_from != :empty AND
release_to != :empty AND
(release_from > :date OR release_to < :date)
;
");
$Statment->bindValue( ':date', $now, \PDO::PARAM_STR );
$Statment->bindValue( ':empty', '0000-00-00 00:00:00', \PDO::PARAM_STR );
$Statment->execute();
$result = $Statment->fetchAll( \PDO::FETCH_ASSOC );
foreach ( $result as $entry )
{
try
{
$Site = $Project->get( (int)$entry['id'] );
$Site->deactivate();
$deactivate[] = (int)$entry['id'];
} catch ( \QUI\Exception $Exception )
{
\QUI\System\Log::writeException( $Exception );
}
}
/**
* activate sites
*/
$Statment = $PDO->prepare("
SELECT id
FROM {$Project->getAttribute('db_table')}
WHERE active = 0 AND
release_from != :empty AND
release_to != :empty AND
release_to >= :date AND
release_from <= :date
;
");
$Statment->bindValue( ':date', $now, \PDO::PARAM_STR );
$Statment->bindValue( ':empty', '0000-00-00 00:00:00', \PDO::PARAM_STR );
$Statment->execute();
$result = $Statment->fetchAll( \PDO::FETCH_ASSOC );
foreach ( $result as $entry )
{
try
{
$Site = $Project->get( (int)$entry['id'] );
$Site->activate();
$activate[] = (int)$entry['id'];
} catch ( \QUI\Exception $Exception )
{
\QUI\System\Log::writeException( $Exception );
}
}
\QUI\System\Log::addInfo(
'Folgende Seiten wurden deaktiviert: '. implode(',', $deactivate)
);
\QUI\System\Log::addInfo(
'Folgende Seiten wurden aktiviert: '. implode(',', $activate)
);
}
}
\ No newline at end of file
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren