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; 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) { public static function issetelse($var, $default = null) {
if (isset($var)) { if (isset($var)) {
return $var; return $var;

View File

@@ -104,6 +104,14 @@ class RippingCluster_Source {
return $longest_index; return $longest_index;
} }
/**
* Permanently deletes this source from disk
*
*/
public function delete() {
RippingCluster_Source_PluginFactory::delete($this->plugin, $this->filename);
}
public function filename() { public function filename() {
return $this->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); 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 * @param string $source_filename Filename of the source
* @return bool * @return bool
*/ */
public static function isValidSource($source_filename); 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; 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; 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; 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); 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);
}
} }
?> ?>

View File

@@ -0,0 +1,28 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
// Grab the name of this source
$encoded_filename = null;
if ($req->get('confirm')) {
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false);
$source->delete();
// Redirect back to the sources page
RippingCluster_Page::redirect('rips/sources');
} else {
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false);
$this->smarty->assign('source', $source);
}
?>

View File

@@ -20,7 +20,8 @@
{assign var='source_cached' value="$source->isCached()} {assign var='source_cached' value="$source->isCached()}
<li> <li>
[ <a href="{$base_uri}rips/source-details/plugin/{$source_plugin}/id/{$source_filename_encoded}" title="Browse source details">Browse</a> | [ <a href="{$base_uri}rips/source-details/plugin/{$source_plugin}/id/{$source_filename_encoded}" title="Browse source details">Browse</a> |
<a href="{$base_uri}rips/setup-rip/plugin/{$source_plugin}/id/{$source_filename_encoded}" title="Rip this source">Rip</a> ] <a href="{$base_uri}rips/setup-rip/plugin/{$source_plugin}/id/{$source_filename_encoded}" title="Rip this source">Rip</a> |
<a href="{$base_uri}sources/delete/plugin/{$source_plugin}/id/{$source_filename_encoded}" title="Delete this source">Delete</a> ]
{$source_filename|escape:'html'}{if $source_cached} (cached){/if} {$source_filename|escape:'html'}{if $source_cached} (cached){/if}
</li> </li>
{/foreach} {/foreach}

View File

@@ -0,0 +1,7 @@
<h2>Delete Source</h2>
<p>
Are you sure you want to delete {$source->plugin()|escape:"html"}:{$source->filename()|escape:"html"}?
[ <a href="{$base_uri}sources/delete/plugin/{$source->plugin()}/id/{$source->filenameEncoded()}/confirm" title="Delete it">Delete</a>
| <a href="{$base_uri}rips/sources" title="Return to sources list">Cancel</a> ]
</p>