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.
This commit is contained in:
@@ -7,14 +7,15 @@ class RippingCluster_Source {
|
|||||||
const PM_AUDIO = 2;
|
const PM_AUDIO = 2;
|
||||||
const PM_SUBTITLE = 3;
|
const PM_SUBTITLE = 3;
|
||||||
|
|
||||||
|
protected $exists;
|
||||||
protected $filename;
|
protected $filename;
|
||||||
protected $plugin;
|
protected $plugin;
|
||||||
protected $titles = array();
|
protected $titles = array();
|
||||||
|
|
||||||
public function __construct($source_filename, $plugin) {
|
public function __construct($source_filename, $plugin, $exists) {
|
||||||
|
$this->exists = $exists;
|
||||||
$this->filename = $source_filename;
|
$this->filename = $source_filename;
|
||||||
$this->plugin = $plugin;
|
$this->plugin = $plugin;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isCached($source_filename) {
|
public static function isCached($source_filename) {
|
||||||
@@ -26,6 +27,10 @@ class RippingCluster_Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function cache() {
|
public function cache() {
|
||||||
|
if (!$this->exists) {
|
||||||
|
throw new RippingCluster_Exception_InvalidSourceDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
$main = RippingCluster_Main::instance();
|
$main = RippingCluster_Main::instance();
|
||||||
$cache = $main->cache();
|
$cache = $main->cache();
|
||||||
$config = $main->config();
|
$config = $main->config();
|
||||||
@@ -38,10 +43,18 @@ class RippingCluster_Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function addTitle(RippingCluster_Rips_SourceTitle $title) {
|
public function addTitle(RippingCluster_Rips_SourceTitle $title) {
|
||||||
|
if (!$this->exists) {
|
||||||
|
throw new RippingCluster_Exception_InvalidSourceDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
$this->titles[] = $title;
|
$this->titles[] = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function longestTitle() {
|
public function longestTitle() {
|
||||||
|
if (!$this->exists) {
|
||||||
|
throw new RippingCluster_Exception_InvalidSourceDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
$longest_title = null;
|
$longest_title = null;
|
||||||
$maximum_duration = 0;
|
$maximum_duration = 0;
|
||||||
|
|
||||||
@@ -61,6 +74,10 @@ class RippingCluster_Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function longestTitleIndex() {
|
public function longestTitleIndex() {
|
||||||
|
if (!$this->exists) {
|
||||||
|
throw new RippingCluster_Exception_InvalidSourceDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
$longest_index = null;
|
$longest_index = null;
|
||||||
$maximmum_duration = 0;
|
$maximmum_duration = 0;
|
||||||
|
|
||||||
@@ -93,10 +110,18 @@ class RippingCluster_Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function titleCount() {
|
public function titleCount() {
|
||||||
|
if (!$this->exists) {
|
||||||
|
throw new RippingCluster_Exception_InvalidSourceDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
return count($this->titles);
|
return count($this->titles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function titles() {
|
public function titles() {
|
||||||
|
if (!$this->exists) {
|
||||||
|
throw new RippingCluster_Exception_InvalidSourceDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->titles;
|
return $this->titles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// Ensure the source is a valid directory, and lies below the configured source_dir
|
||||||
if ( ! self::isValidSource($source_filename)) {
|
if ( ! self::isValidSource($source_filename)) {
|
||||||
throw new RippingCluster_Exception_InvalidSourceDirectory($source_filename);
|
return new RippingCluster_Source($source_filename, self::name(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$source = null;
|
$source = null;
|
||||||
if ($use_cache && $cache->exists($source_filename)) {
|
if ($use_cache && $cache->exists($source_filename)) {
|
||||||
$source = unserialize($cache->fetch($source_filename));
|
$source = unserialize($cache->fetch($source_filename));
|
||||||
} else {
|
} else {
|
||||||
$source = new RippingCluster_Source($source_filename, self::name());
|
$source = new RippingCluster_Source($source_filename, self::name(), true);
|
||||||
|
|
||||||
if ($scan) {
|
if ($scan) {
|
||||||
$source_shell = escapeshellarg($source_filename);
|
$source_shell = escapeshellarg($source_filename);
|
||||||
|
|||||||
Reference in New Issue
Block a user