Add option to delete sources with support in all three backends

This commit is contained in:
2010-11-19 22:24:12 +00:00
parent 73e42a42b1
commit fa7b54b861
10 changed files with 128 additions and 2 deletions

View File

@@ -169,6 +169,21 @@ class RippingCluster_Main {
return true;
}
public static function rmdir_recursive($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") self::rmdir_recursive($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
return true;
}
public static function issetelse($var, $default = null) {
if (isset($var)) {
return $var;

View File

@@ -104,6 +104,14 @@ class RippingCluster_Source {
return $longest_index;
}
/**
* Permanently deletes this source from disk
*
*/
public function delete() {
RippingCluster_Source_PluginFactory::delete($this->plugin, $this->filename);
}
public function filename() {
return $this->filename;

View File

@@ -41,13 +41,21 @@ interface RippingCluster_Source_IPlugin extends RippingCluster_IPlugin {
public static function loadEncoded($encoded_filename, $scan = true, $use_cache = true);
/**
* Determins if a filename is a valid source loadable using this plugin
* Determines if a filename is a valid source loadable using this plugin
*
* @param string $source_filename Filename of the source
* @return bool
*/
public static function isValidSource($source_filename);
/**
* Permanently deletes the given source from disk
*
* @param RippingCluster_Source $source Source object to be deleted
* @return bool
*/
public static function delete($source_filename);
}
?>

View File

@@ -117,6 +117,20 @@ class RippingCluster_Source_Plugin_Bluray extends RippingCluster_PluginBase impl
return true;
}
/**
* Permanently deletes the given source from disk
*
* @param RippingCluster_Source $source Source object to be deleted
* @return bool
*/
public static function delete($source_filename) {
if ( ! self::isValidSource($source_filename)) {
return false;
}
return RippingCluster_Main::rmdir_recursive($source_filename);
}
}
?>

View File

@@ -217,6 +217,21 @@ class RippingCluster_Source_Plugin_HandBrake extends RippingCluster_PluginBase i
return false;
}
/**
* Permanently deletes the given source from disk
*
* @param RippingCluster_Source $source Source object to be deleted
* @return bool
*/
public static function delete($source_filename) {
if ( ! self::isValidSource($source_filename)) {
return false;
}
return RippingCluster_Main::rmdir_recursive($source_filename);
}
}
?>

View File

@@ -244,6 +244,20 @@ class RippingCluster_Source_Plugin_MkvInfo extends RippingCluster_PluginBase imp
return true;
}
/**
* Permanently deletes the given source from disk
*
* @param RippingCluster_Source $source Source object to be deleted
* @return bool
*/
public static function delete($source_filename) {
if ( ! self::isValidSource($source_filename)) {
return false;
}
return unlink($source_filename);
}
}
?>

View File

@@ -67,6 +67,22 @@ class RippingCluster_Source_PluginFactory extends RippingCluster_PluginFactory {
return call_user_func(array(self::classname($plugin), 'isValidSource'), source_filename);
}
/**
* Permanently deletes the given source from disk
*
* @param string $plugin Name of the plugin used to load the source
* @param string $source_filename Filename of the source to be deleted
*/
public static function delete($plugin, $source_filename) {
self::ensureScanned();
if ( ! self::isValidPlugin($plugin)) {
return null;
}
return call_user_func(array(self::classname($plugin), 'delete'), $source_filename);
}
}
?>