From 802fd308c1831600bdf3b8514672987508bb40b9 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 1 Sep 2010 20:11:43 +0100 Subject: [PATCH] Allow source object to be created even if dir doesn't exist A job may remain in the database after the source dir has been deleted. The source object has been changed to permit construction even if the source it represents doesn't exist, but will throw an exception if any requests are made of the object. --- lib/RippingCluster/Source.class.php | 33 ++++++++++++++++--- .../Source/Plugin/HandBrake.class.php | 6 ++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/RippingCluster/Source.class.php b/lib/RippingCluster/Source.class.php index e6e0556..e602767 100644 --- a/lib/RippingCluster/Source.class.php +++ b/lib/RippingCluster/Source.class.php @@ -7,14 +7,15 @@ class RippingCluster_Source { const PM_AUDIO = 2; const PM_SUBTITLE = 3; + protected $exists; protected $filename; protected $plugin; protected $titles = array(); - public function __construct($source_filename, $plugin) { + public function __construct($source_filename, $plugin, $exists) { + $this->exists = $exists; $this->filename = $source_filename; - $this->plugin = $plugin; - + $this->plugin = $plugin; } public static function isCached($source_filename) { @@ -26,6 +27,10 @@ class RippingCluster_Source { } public function cache() { + if (!$this->exists) { + throw new RippingCluster_Exception_InvalidSourceDirectory(); + } + $main = RippingCluster_Main::instance(); $cache = $main->cache(); $config = $main->config(); @@ -38,11 +43,19 @@ class RippingCluster_Source { } public function addTitle(RippingCluster_Rips_SourceTitle $title) { + if (!$this->exists) { + throw new RippingCluster_Exception_InvalidSourceDirectory(); + } + $this->titles[] = $title; } public function longestTitle() { - $longest_title = null; + if (!$this->exists) { + throw new RippingCluster_Exception_InvalidSourceDirectory(); + } + + $longest_title = null; $maximum_duration = 0; if ( ! $this->titles) { @@ -61,6 +74,10 @@ class RippingCluster_Source { } public function longestTitleIndex() { + if (!$this->exists) { + throw new RippingCluster_Exception_InvalidSourceDirectory(); + } + $longest_index = null; $maximmum_duration = 0; @@ -93,10 +110,18 @@ class RippingCluster_Source { } public function titleCount() { + if (!$this->exists) { + throw new RippingCluster_Exception_InvalidSourceDirectory(); + } + return count($this->titles); } public function titles() { + if (!$this->exists) { + throw new RippingCluster_Exception_InvalidSourceDirectory(); + } + return $this->titles; } diff --git a/lib/RippingCluster/Source/Plugin/HandBrake.class.php b/lib/RippingCluster/Source/Plugin/HandBrake.class.php index a1a2af1..2cb734f 100644 --- a/lib/RippingCluster/Source/Plugin/HandBrake.class.php +++ b/lib/RippingCluster/Source/Plugin/HandBrake.class.php @@ -8,7 +8,7 @@ class RippingCluster_Source_Plugin_HandBrake implements RippingCluster_Source_IP const PM_CHAPTER = 1; const PM_AUDIO = 2; const PM_SUBTITLE = 3; - + public static function init() { // Nothing to do } @@ -48,14 +48,14 @@ class RippingCluster_Source_Plugin_HandBrake implements RippingCluster_Source_IP // Ensure the source is a valid directory, and lies below the configured source_dir if ( ! self::isValidSource($source_filename)) { - throw new RippingCluster_Exception_InvalidSourceDirectory($source_filename); + return new RippingCluster_Source($source_filename, self::name(), false); } $source = null; if ($use_cache && $cache->exists($source_filename)) { $source = unserialize($cache->fetch($source_filename)); } else { - $source = new RippingCluster_Source($source_filename, self::name()); + $source = new RippingCluster_Source($source_filename, self::name(), true); if ($scan) { $source_shell = escapeshellarg($source_filename);