From 4e85b423354d8b715d12540fbd2ac79a66de3399 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 19:56:22 +0100 Subject: add download-command cli interface & config --- config.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'config.php') diff --git a/config.php b/config.php index 1dbea27..57be966 100644 --- a/config.php +++ b/config.php @@ -24,7 +24,7 @@ $GLOBALS['CONFIG']['PREVIEW_DOMAIN'] = 'xlocalhost'; * Protokollfreie URLs (welche, die mit // beginnen), werden automatisch mit dem korrekten Protokoll ergänzt. * In diesem Fall wird auch ein SSL-Umschalt-Button im Header angezeigt */ -if($_SERVER['SERVER_NAME'] == 'localhost') +if(@$_SERVER['SERVER_NAME'] == 'localhost') { // keine Konfiguration -> BASEURL wird automatisch erraten } @@ -38,3 +38,28 @@ else // Set a safe Default $GLOBALS['CONFIG']['BASEURL'] = '//streaming.media.ccc.de/'; } + + +/** + * Konfiguration für den Datei-Download Cronjob + */ +$GLOBALS['CONFIG']['DOWNLOAD'] = [ + /** + * Verweigeren Download, wenn der PHP-Prozess unter einem anderen Benutzer als diesem läuft + * Auskommentieren um alle Benutzer zu erlauben + */ + //'REQUIRE_USER' => 'www-data', + + /** + * Wartende HTTP-Downloads nach dieser Anzahl von Sekunden abbrechen + */ + 'HTTP_TIMEOUT' => 5 /* Sekunden */, + + /** + * Nur Dateien von Konferenzen herunterladen, die weniger als + * diese Aanzahl von Tagen alt sind (gemessen am END_DATE) + * + * Auskommentieren, um alle Konferenzen zu beachten + */ + 'MAX_CONFERENCE_AGE' => 30 /* Tage */, +]; -- cgit v1.3.1 From 8beec6fda376b842a9ddb7a2425829690f0a8b48 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 20:27:35 +0100 Subject: use DateTime objects for ends/startsAt --- command/download.php | 32 +++++++++++++++++++++++++------- config.php | 2 +- model/Conference.php | 16 ++++++++++++---- model/Conferences.php | 2 +- 4 files changed, 39 insertions(+), 13 deletions(-) (limited to 'config.php') diff --git a/command/download.php b/command/download.php index 8cc2f53..cb0987d 100644 --- a/command/download.php +++ b/command/download.php @@ -15,14 +15,32 @@ if(isset($conf['REQUIRE_USER'])) } } -foreach (Conferences::getConferences() as $conference) +$conferences = Conferences::getConferences(); + +if(isset($conf['MAX_CONFERENCE_AGE'])) { - stdout('== %s ==', $conference->getSlug()); + $months = intval($conf['MAX_CONFERENCE_AGE']); + $conferencesAfter = new DateTime(); + $conferencesAfter->sub(new DateInterval('P'.$months.'D')); - if(isset($conf['MAX_CONFERENCE_AGE'])) - { - date_diff() - return time() >= $this->endsAt(); - } + stdout('Filtering before %s', $conferencesAfter->format('Y-m-d')); + $conferences = array_filter($conferences, function($conference) use ($conferencesAfter) { + $isBefore = $conference->endsAt() < $conferencesAfter; + + if($isBefore) { + stdout( + ' %s: %s', + $conference->endsAt()->format('Y-m-d'), + $conference->getSlug() + ); + } + return !$isBefore; + }); +} + +stdout(''); +foreach ($conferences as $conference) +{ + stdout('== %s ==', $conference->getSlug()); } diff --git a/config.php b/config.php index 57be966..1b5e84f 100644 --- a/config.php +++ b/config.php @@ -61,5 +61,5 @@ $GLOBALS['CONFIG']['DOWNLOAD'] = [ * * Auskommentieren, um alle Konferenzen zu beachten */ - 'MAX_CONFERENCE_AGE' => 30 /* Tage */, + 'MAX_CONFERENCE_AGE' => 14 /* Tage */, ]; diff --git a/model/Conference.php b/model/Conference.php index 07d72dd..ae5ab41 100644 --- a/model/Conference.php +++ b/model/Conference.php @@ -33,11 +33,17 @@ class Conference extends ModelBase } public function startsAt() { - return $this->get('CONFERENCE.STARTS_AT'); + if(!$this->has('CONFERENCE.STARTS_AT')) + return null; + + return DateTime::createFromFormat('U', $this->get('CONFERENCE.STARTS_AT')); } public function endsAt() { - return $this->get('CONFERENCE.ENDS_AT'); + if(!$this->has('CONFERENCE.ENDS_AT')) + return null; + + return DateTime::createFromFormat('U', $this->get('CONFERENCE.ENDS_AT')); } public function hasBegun() { @@ -62,7 +68,8 @@ class Conference extends ModelBase } if($this->has('CONFERENCE.STARTS_AT')) { - return time() >= $this->get('CONFERENCE.STARTS_AT'); + $now = new DateTime('now'); + return $now >= $this->startsAt(); } else { return true; } @@ -84,7 +91,8 @@ class Conference extends ModelBase } if($this->has('CONFERENCE.ENDS_AT')) { - return time() >= $this->get('CONFERENCE.ENDS_AT'); + $now = new DateTime('now'); + return $now >= $this->endsAt(); } else { return false; } diff --git a/model/Conferences.php b/model/Conferences.php index 2dc9f35..8de4029 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -48,7 +48,7 @@ class Conferences $sorted = Conferences::getConferences(); usort($sorted, function($a, $b) { - return $b->startsAt() - $a->endsAt(); + return $b->startsAt() > $a->endsAt() ? 1 : -1; }); return $sorted; -- cgit v1.3.1