From 296dc7df94db3f1919fe934776feecb02f34366f Mon Sep 17 00:00:00 2001 From: DanieL Date: Tue, 31 Jan 2023 15:33:06 -0300 Subject: [PATCH] Updates --- objects/video.php | 23 ++++++--- .../Scheduler/Objects/Scheduler_commands.php | 41 +++++++++++++++- plugin/Scheduler/Scheduler.php | 49 ++++++++++++++++++- plugin/Scheduler/install/install.sql | 42 +++++++++------- plugin/Scheduler/install/updateV4.0.sql | 10 ++++ 5 files changed, 138 insertions(+), 27 deletions(-) create mode 100644 plugin/Scheduler/install/updateV4.0.sql diff --git a/objects/video.php b/objects/video.php index fb6fc82acd..6286a2da35 100644 --- a/objects/video.php +++ b/objects/video.php @@ -71,6 +71,7 @@ if (!class_exists('Video')) { 'a' => 'Active', 'k' => 'Active and Encoding', 'i' => 'Inactive', + 'h' => 'Scheduled Release Date', 'e' => 'Encoding', 'x' => 'Encoding Error', 'd' => 'Downloading', @@ -85,6 +86,7 @@ if (!class_exists('Video')) { 'a' => '', 'k' => '', 'i' => '', + 'h' => '', 'e' => '', 'x' => '', 'd' => '', @@ -98,6 +100,7 @@ if (!class_exists('Video')) { public static $statusActive = 'a'; public static $statusActiveAndEncoding = 'k'; public static $statusInactive = 'i'; + public static $statusScheduledReleaseDate = 'h'; public static $statusEncoding = 'e'; public static $statusEncodingError = 'x'; public static $statusDownloading = 'd'; @@ -701,17 +704,24 @@ if (!class_exists('Video')) { if (!empty($_REQUEST['overrideStatus'])) { return $this->setStatus($_REQUEST['overrideStatus']); } else { // encoder did not provide a status - if (!empty($_REQUEST['keepEncoding'])) { - return $this->setStatus(Video::$statusActiveAndEncoding); - } else { - if ($this->getTitle() !== "Video automatically booked") { - return $this->setStatus($advancedCustom->defaultVideoStatus); + AVideoPlugin::loadPlugin('Scheduler'); + $row = Scheduler::isActiveFromVideosId($this->id); + if(!empty($row)){ // there is a schedule to activate the video + return $this->setStatus(Video::$statusScheduledReleaseDate); + }else{ + if (!empty($_REQUEST['keepEncoding'])) { + return $this->setStatus(Video::$statusActiveAndEncoding); } else { - return $this->setStatus(Video::$statusInactive); + if ($this->getTitle() !== "Video automatically booked") { + return $this->setStatus($advancedCustom->defaultVideoStatus); + } else { + return $this->setStatus(Video::$statusInactive); + } } } } } + return $this->setStatus($default); } @@ -5798,6 +5808,7 @@ $statusThatShowTheCompleteMenu = array( $statusSearchFilter = array( Video::$statusActive, Video::$statusInactive, + Video::$statusScheduledReleaseDate, Video::$statusEncoding, Video::$statusTranfering, Video::$statusUnlisted, diff --git a/plugin/Scheduler/Objects/Scheduler_commands.php b/plugin/Scheduler/Objects/Scheduler_commands.php index 7ef3d8606d..1c0ac041e0 100644 --- a/plugin/Scheduler/Objects/Scheduler_commands.php +++ b/plugin/Scheduler/Objects/Scheduler_commands.php @@ -12,7 +12,7 @@ class Scheduler_commands extends ObjectYPT { protected $id, $callbackURL, $parameters, $date_to_execute, $executed_in, $status, $callbackResponse, $timezone, $repeat_minute, $repeat_hour, $repeat_day_of_month, $repeat_month, - $repeat_day_of_week, $type; + $repeat_day_of_week, $type, $videos; static function getSearchFieldsNames() { return array('callbackURL', 'parameters'); @@ -22,6 +22,34 @@ class Scheduler_commands extends ObjectYPT { return 'scheduler_commands'; } + static function isActiveFromVideosId($videos_id){ + $row = self::getFromVideosId($videos_id); + + if(!empty($row) && $row['status'] == self::$statusActive ){ + return true; + } + return false; + } + + static function getFromVideosId($videos_id){ + global $global; + $videos_id = intval($videos_id); + if(empty($videos_id)){ + return false; + } + $sql = "SELECT * FROM " . static::getTableName() . " WHERE videos_id = ? LIMIT 1"; + // I had to add this because the about from customize plugin was not loading on the about page http://127.0.0.1/AVideo/about + $res = sqlDAL::readSql($sql, "i", [$videos_id], true); + $data = sqlDAL::fetchAssoc($res); + sqlDAL::close($res); + if ($res) { + $row = $data; + } else { + $row = false; + } + return $row; + } + public static function getTimesNow() { $minute = intval(date('i')); $hour = intval(date('H')); @@ -176,7 +204,15 @@ class Scheduler_commands extends ObjectYPT { private function _setTimezone($timezone) { $this->timezone = $timezone; } + + public function getVideos() { + return $this->videos; + } + public function setVideos($videos): void { + $this->videos = $videos; + } + public function save() { if (empty($this->date_to_execute)) { $this->date_to_execute = 'NULL'; @@ -208,6 +244,9 @@ class Scheduler_commands extends ObjectYPT { if (empty($this->callbackURL)) { $this->callbackURL = ''; } + if (empty($this->videos_id)) { + $this->videos_id = 'NULL'; + } $this->_setTimeZone(date_default_timezone_get()); diff --git a/plugin/Scheduler/Scheduler.php b/plugin/Scheduler/Scheduler.php index ac26987ea3..149fbf6eb6 100644 --- a/plugin/Scheduler/Scheduler.php +++ b/plugin/Scheduler/Scheduler.php @@ -30,7 +30,7 @@ class Scheduler extends PluginAbstract { } public function getPluginVersion() { - return "3.0"; + return "4.0"; } public function updateScript() { @@ -84,7 +84,16 @@ class Scheduler extends PluginAbstract { if (!isset($_executeSchelude)) { $_executeSchelude = array(); } - $e = new Scheduler_commands($scheduler_commands_id); + $e = new Scheduler_commands($scheduler_commands_id); + + $videos_id = $e->getCallbackURL(); + if(!empty($videos_id)){ // make it active + $video = new Video('', '', $videos_id); + $status = $video->setStatus(Video::$statusActive); + AVideoPlugin::onNewVideo($videos_id); + return $e->setExecuted($videos_id); + } + $callBackURL = $e->getCallbackURL(); $callBackURL = str_replace('{webSiteRootURL}', $global['webSiteRootURL'], $callBackURL); if (!isValidURL($callBackURL)) { @@ -108,6 +117,42 @@ class Scheduler extends PluginAbstract { return false; } + static function isActiveFromVideosId($videos_id){ + return Scheduler_commands::isActiveFromVideosId($videos_id);; + } + + static public function addVideoToRelease($date_to_execute, $videos_id) { + _error_log("Scheduler::addVideoToRelease [$date_to_execute] [$videos_id]"); + if (empty($date_to_execute)) { + _error_log("Scheduler::addVideoToRelease ERROR date_to_execute is empty"); + return false; + } + + $date_to_execute_time = _strtotime($date_to_execute); + + if ($date_to_execute_time <= time()) { + _error_log("Scheduler::addVideoToRelease ERROR date_to_execute must be greater than now [{$date_to_execute}] " . date('Y/m/d H:i:s', $date_to_execute_time) . ' ' . date('Y/m/d H:i:s')); + return false; + } + + if (empty($videos_id)) { + _error_log("Scheduler::addVideoToRelease ERROR videos_id is empty"); + return false; + } + + $id = 0; + $row = Scheduler_commands::getFromVideosId($videos_id); + if(!empty($row)){ + $id = $row['id']; + } + + $e = new Scheduler_commands($id); + $e->setDate_to_execute($date_to_execute); + $e->setVideos_id($videos_id); + + return $e->save(); + } + static public function add($date_to_execute, $callbackURL, $parameters = '', $type = '') { _error_log("Scheduler::add [$date_to_execute] [$callbackURL]"); if (empty($date_to_execute)) { diff --git a/plugin/Scheduler/install/install.sql b/plugin/Scheduler/install/install.sql index dab2a627cf..a8f93a2762 100644 --- a/plugin/Scheduler/install/install.sql +++ b/plugin/Scheduler/install/install.sql @@ -1,19 +1,25 @@ -CREATE TABLE IF NOT EXISTS `scheduler_commands` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `callbackURL` VARCHAR(255) NOT NULL, - `parameters` TEXT NULL DEFAULT NULL, - `created` DATETIME NULL DEFAULT NULL, - `modified` DATETIME NULL DEFAULT NULL, - `date_to_execute` DATETIME NULL, - `executed_in` DATETIME NULL DEFAULT NULL, - `status` CHAR(1) NOT NULL DEFAULT 'a', - `callbackResponse` TEXT NULL DEFAULT NULL, - `timezone` VARCHAR(255) NULL, - `repeat_minute` INT NULL, - `repeat_hour` INT NULL, - `repeat_day_of_month` INT NULL, - `repeat_month` INT NULL, - `repeat_day_of_week` INT NULL, - `type` VARCHAR(45) NULL, - PRIMARY KEY (`id`)) +CREATE TABLE IF NOT EXISTS `scheduler_commands` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `callbackURL` VARCHAR(255) NOT NULL, + `parameters` TEXT NULL DEFAULT NULL, + `created` DATETIME NULL DEFAULT NULL, + `modified` DATETIME NULL DEFAULT NULL, + `date_to_execute` DATETIME NULL, + `executed_in` DATETIME NULL DEFAULT NULL, + `status` CHAR(1) NOT NULL DEFAULT 'a', + `callbackResponse` TEXT NULL DEFAULT NULL, + `timezone` VARCHAR(255) NULL, + `repeat_minute` INT NULL, + `repeat_hour` INT NULL, + `repeat_day_of_month` INT NULL, + `repeat_month` INT NULL, + `day_of_week` INT NULL, + `videos_id` INT(11) NULL, + PRIMARY KEY (`id`), + INDEX `fk_scheduler_commands_videos1_idx` (`videos_id` ASC) VISIBLE, + CONSTRAINT `fk_scheduler_commands_videos1` + FOREIGN KEY (`videos_id`) + REFERENCES `videos` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE) ENGINE = InnoDB; \ No newline at end of file diff --git a/plugin/Scheduler/install/updateV4.0.sql b/plugin/Scheduler/install/updateV4.0.sql new file mode 100644 index 0000000000..b3ef9050b5 --- /dev/null +++ b/plugin/Scheduler/install/updateV4.0.sql @@ -0,0 +1,10 @@ +ALTER TABLE `scheduler_commands` +ADD COLUMN `videos_id` INT(11) NULL DEFAULT NULL, +ADD INDEX `fk_scheduler_commands_videos1_idx` (`videos_id` ASC); + +ALTER TABLE `scheduler_commands` +ADD CONSTRAINT `fk_scheduler_commands_videos1` + FOREIGN KEY (`videos_id`) + REFERENCES `videos` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE