CC-2977: Never delete files from the database

- Files are marked deleted(file_exists to false) on deletion.
- Dirs are marked removed(removed flag to true) on removal of watched
folder in a usual way. If dir is unmounted, without being removed from
watched list first, it will be marked as not exists(exist flag to false)
- Manage Media Folders will show if dirs exist or not( mounted or not)
- Playlist builder will show if files exists or not
This commit is contained in:
James 2012-01-11 12:17:48 -05:00
parent 61c5355e8a
commit 04b48d47cc
16 changed files with 374 additions and 69 deletions

View file

@ -41,6 +41,7 @@ class CcMusicDirsTableMap extends TableMap {
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addColumn('DIRECTORY', 'Directory', 'LONGVARCHAR', false, null, null);
$this->addColumn('TYPE', 'Type', 'VARCHAR', false, 255, null);
$this->addColumn('EXISTS', 'Exists', 'BOOLEAN', false, null, true);
$this->addColumn('REMOVED', 'Removed', 'BOOLEAN', false, null, false);
// validators
} // initialize()

View file

@ -42,6 +42,13 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
*/
protected $type;
/**
* The value for the exists field.
* Note: this column has a database default value of: true
* @var boolean
*/
protected $exists;
/**
* The value for the removed field.
* Note: this column has a database default value of: false
@ -76,6 +83,7 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
*/
public function applyDefaultValues()
{
$this->exists = true;
$this->removed = false;
}
@ -119,6 +127,16 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
return $this->type;
}
/**
* Get the [exists] column value.
*
* @return boolean
*/
public function getExists()
{
return $this->exists;
}
/**
* Get the [removed] column value.
*
@ -189,6 +207,27 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
return $this;
} // setType()
/**
* Set the value of [exists] column.
*
* @param boolean $v new value
* @return CcMusicDirs The current object (for fluent API support)
*/
public function setExists($v)
{
Logging::log("setting exists to ".print_r($v, true));
if ($v !== null) {
$v = (boolean) $v;
}
if ($this->exists !== $v || $this->isNew()) {
$this->exists = $v;
$this->modifiedColumns[] = CcMusicDirsPeer::EXISTS;
}
return $this;
} // setExists()
/**
* Set the value of [removed] column.
*
@ -219,6 +258,10 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
*/
public function hasOnlyDefaultValues()
{
if ($this->exists !== true) {
return false;
}
if ($this->removed !== false) {
return false;
}
@ -248,7 +291,8 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
$this->directory = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
$this->type = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
$this->removed = ($row[$startcol + 3] !== null) ? (boolean) $row[$startcol + 3] : null;
$this->exists = ($row[$startcol + 3] !== null) ? (boolean) $row[$startcol + 3] : null;
$this->removed = ($row[$startcol + 4] !== null) ? (boolean) $row[$startcol + 4] : null;
$this->resetModified();
$this->setNew(false);
@ -257,7 +301,7 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
$this->ensureConsistency();
}
return $startcol + 4; // 4 = CcMusicDirsPeer::NUM_COLUMNS - CcMusicDirsPeer::NUM_LAZY_LOAD_COLUMNS).
return $startcol + 5; // 5 = CcMusicDirsPeer::NUM_COLUMNS - CcMusicDirsPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating CcMusicDirs object", $e);
@ -584,6 +628,9 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
return $this->getType();
break;
case 3:
return $this->getExists();
break;
case 4:
return $this->getRemoved();
break;
default:
@ -612,7 +659,8 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
$keys[0] => $this->getId(),
$keys[1] => $this->getDirectory(),
$keys[2] => $this->getType(),
$keys[3] => $this->getRemoved(),
$keys[3] => $this->getExists(),
$keys[4] => $this->getRemoved(),
);
return $result;
}
@ -654,6 +702,9 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
$this->setType($value);
break;
case 3:
$this->setExists($value);
break;
case 4:
$this->setRemoved($value);
break;
} // switch()
@ -683,7 +734,8 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setDirectory($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]);
if (array_key_exists($keys[3], $arr)) $this->setRemoved($arr[$keys[3]]);
if (array_key_exists($keys[3], $arr)) $this->setExists($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setRemoved($arr[$keys[4]]);
}
/**
@ -698,6 +750,7 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
if ($this->isColumnModified(CcMusicDirsPeer::ID)) $criteria->add(CcMusicDirsPeer::ID, $this->id);
if ($this->isColumnModified(CcMusicDirsPeer::DIRECTORY)) $criteria->add(CcMusicDirsPeer::DIRECTORY, $this->directory);
if ($this->isColumnModified(CcMusicDirsPeer::TYPE)) $criteria->add(CcMusicDirsPeer::TYPE, $this->type);
if ($this->isColumnModified(CcMusicDirsPeer::EXISTS)) $criteria->add(CcMusicDirsPeer::EXISTS, $this->exists);
if ($this->isColumnModified(CcMusicDirsPeer::REMOVED)) $criteria->add(CcMusicDirsPeer::REMOVED, $this->removed);
return $criteria;
@ -762,6 +815,7 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
{
$copyObj->setDirectory($this->directory);
$copyObj->setType($this->type);
$copyObj->setExists($this->exists);
$copyObj->setRemoved($this->removed);
if ($deepCopy) {
@ -962,6 +1016,7 @@ abstract class BaseCcMusicDirs extends BaseObject implements Persistent
$this->id = null;
$this->directory = null;
$this->type = null;
$this->exists = null;
$this->removed = null;
$this->alreadyInSave = false;
$this->alreadyInValidation = false;

View file

@ -26,7 +26,7 @@ abstract class BaseCcMusicDirsPeer {
const TM_CLASS = 'CcMusicDirsTableMap';
/** The total number of columns. */
const NUM_COLUMNS = 4;
const NUM_COLUMNS = 5;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
@ -40,6 +40,9 @@ abstract class BaseCcMusicDirsPeer {
/** the column name for the TYPE field */
const TYPE = 'cc_music_dirs.TYPE';
/** the column name for the EXISTS field */
const EXISTS = 'cc_music_dirs.EXISTS';
/** the column name for the REMOVED field */
const REMOVED = 'cc_music_dirs.REMOVED';
@ -59,12 +62,12 @@ abstract class BaseCcMusicDirsPeer {
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('Id', 'Directory', 'Type', 'Removed', ),
BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'directory', 'type', 'removed', ),
BasePeer::TYPE_COLNAME => array (self::ID, self::DIRECTORY, self::TYPE, self::REMOVED, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID', 'DIRECTORY', 'TYPE', 'REMOVED', ),
BasePeer::TYPE_FIELDNAME => array ('id', 'directory', 'type', 'removed', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
BasePeer::TYPE_PHPNAME => array ('Id', 'Directory', 'Type', 'Exists', 'Removed', ),
BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'directory', 'type', 'exists', 'removed', ),
BasePeer::TYPE_COLNAME => array (self::ID, self::DIRECTORY, self::TYPE, self::EXISTS, self::REMOVED, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID', 'DIRECTORY', 'TYPE', 'EXISTS', 'REMOVED', ),
BasePeer::TYPE_FIELDNAME => array ('id', 'directory', 'type', 'exists', 'removed', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
);
/**
@ -74,12 +77,12 @@ abstract class BaseCcMusicDirsPeer {
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Directory' => 1, 'Type' => 2, 'Removed' => 3, ),
BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'directory' => 1, 'type' => 2, 'removed' => 3, ),
BasePeer::TYPE_COLNAME => array (self::ID => 0, self::DIRECTORY => 1, self::TYPE => 2, self::REMOVED => 3, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'DIRECTORY' => 1, 'TYPE' => 2, 'REMOVED' => 3, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'directory' => 1, 'type' => 2, 'removed' => 3, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Directory' => 1, 'Type' => 2, 'Exists' => 3, 'Removed' => 4, ),
BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'directory' => 1, 'type' => 2, 'exists' => 3, 'removed' => 4, ),
BasePeer::TYPE_COLNAME => array (self::ID => 0, self::DIRECTORY => 1, self::TYPE => 2, self::EXISTS => 3, self::REMOVED => 4, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'DIRECTORY' => 1, 'TYPE' => 2, 'EXISTS' => 3, 'REMOVED' => 4, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'directory' => 1, 'type' => 2, 'exists' => 3, 'removed' => 4, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
);
/**
@ -154,11 +157,13 @@ abstract class BaseCcMusicDirsPeer {
$criteria->addSelectColumn(CcMusicDirsPeer::ID);
$criteria->addSelectColumn(CcMusicDirsPeer::DIRECTORY);
$criteria->addSelectColumn(CcMusicDirsPeer::TYPE);
$criteria->addSelectColumn(CcMusicDirsPeer::EXISTS);
$criteria->addSelectColumn(CcMusicDirsPeer::REMOVED);
} else {
$criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.DIRECTORY');
$criteria->addSelectColumn($alias . '.TYPE');
$criteria->addSelectColumn($alias . '.EXISTS');
$criteria->addSelectColumn($alias . '.REMOVED');
}
}

View file

@ -9,11 +9,13 @@
* @method CcMusicDirsQuery orderById($order = Criteria::ASC) Order by the id column
* @method CcMusicDirsQuery orderByDirectory($order = Criteria::ASC) Order by the directory column
* @method CcMusicDirsQuery orderByType($order = Criteria::ASC) Order by the type column
* @method CcMusicDirsQuery orderByExists($order = Criteria::ASC) Order by the exists column
* @method CcMusicDirsQuery orderByRemoved($order = Criteria::ASC) Order by the removed column
*
* @method CcMusicDirsQuery groupById() Group by the id column
* @method CcMusicDirsQuery groupByDirectory() Group by the directory column
* @method CcMusicDirsQuery groupByType() Group by the type column
* @method CcMusicDirsQuery groupByExists() Group by the exists column
* @method CcMusicDirsQuery groupByRemoved() Group by the removed column
*
* @method CcMusicDirsQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
@ -30,11 +32,13 @@
* @method CcMusicDirs findOneById(int $id) Return the first CcMusicDirs filtered by the id column
* @method CcMusicDirs findOneByDirectory(string $directory) Return the first CcMusicDirs filtered by the directory column
* @method CcMusicDirs findOneByType(string $type) Return the first CcMusicDirs filtered by the type column
* @method CcMusicDirs findOneByExists(boolean $exists) Return the first CcMusicDirs filtered by the exists column
* @method CcMusicDirs findOneByRemoved(boolean $removed) Return the first CcMusicDirs filtered by the removed column
*
* @method array findById(int $id) Return CcMusicDirs objects filtered by the id column
* @method array findByDirectory(string $directory) Return CcMusicDirs objects filtered by the directory column
* @method array findByType(string $type) Return CcMusicDirs objects filtered by the type column
* @method array findByExists(boolean $exists) Return CcMusicDirs objects filtered by the exists column
* @method array findByRemoved(boolean $removed) Return CcMusicDirs objects filtered by the removed column
*
* @package propel.generator.airtime.om
@ -206,6 +210,23 @@ abstract class BaseCcMusicDirsQuery extends ModelCriteria
return $this->addUsingAlias(CcMusicDirsPeer::TYPE, $type, $comparison);
}
/**
* Filter the query on the exists column
*
* @param boolean|string $exists The value to use as filter.
* Accepts strings ('false', 'off', '-', 'no', 'n', and '0' are false, the rest is true)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return CcMusicDirsQuery The current query, for fluid interface
*/
public function filterByExists($exists = null, $comparison = null)
{
if (is_string($exists)) {
$exists = in_array(strtolower($exists), array('false', 'off', '-', 'no', 'n', '0')) ? false : true;
}
return $this->addUsingAlias(CcMusicDirsPeer::EXISTS, $exists, $comparison);
}
/**
* Filter the query on the removed column
*