Browse files

Removing skipping of nonexistent files in CouplerBehavior.

This proved to be unexpected behavior.

Allowing records to not have a corresponding file. If you'd still want
to enforce each record having a valid corresponding file you must now
use the sync shell task to detect potential invalid records.

Fixes #50. Refs #49.
  • Loading branch information...
1 parent aee99ac commit 2a188ed85f69a9cf361964b84015c4b21d1137fc @davidpersson davidpersson committed Mar 20, 2011
Showing with 7 additions and 20 deletions.
  1. +6 −19 models/behaviors/coupler.php
  2. +1 −1 tests/cases/models/behaviors/coupler.test.php
View
25 models/behaviors/coupler.php
@@ -153,12 +153,9 @@ function beforeSave(&$Model) {
}
/**
- * Callback
- *
- * Deletes file corresponding to record.
- *
- * If the file couldn't be deleted the callback will stop the
- * delete operation and not continue to delete the record.
+ * Callback, deletes file (if there's one coupled) corresponding to record. If
+ * the file couldn't be deleted the callback will stop the delete operation and
+ * not continue to delete the record.
*
* @param Model $Model
* @param boolean $cascade
@@ -172,8 +169,8 @@ function beforeDelete(&$Model, $cascade = true) {
'fields' => array('dirname', 'basename'),
'recursive' => -1,
));
- if (empty($result)) {
- return false;
+ if (!$result[$Model->alias]['dirname'] || !$result[$Model->alias]['basename']) {
+ return true;
}
$file = $baseDirectory;
@@ -185,13 +182,7 @@ function beforeDelete(&$Model, $cascade = true) {
}
/**
- * Callback
- *
- * Adds the `file` field to each result.
- *
- * If the corresponding file of a result is not readable it is removed
- * from the results array, as it is inconsistent. This can be fixed
- * by calling `cake media sync` from the command line.
+ * Callback, adds the `file` field to each result.
*
* @param Model $Model
* @param array $results
@@ -213,10 +204,6 @@ function afterFind(&$Model, $results, $primary = false) {
$file .= DS . $result[$Model->alias]['basename'];
$file = str_replace(array('\\', '/'), DS, $file);
- if (!is_file($file)) {
- unset($results[$key]);
- continue;
- }
$result[$Model->alias]['file'] = $file;
}
return $results;
View
2 tests/cases/models/behaviors/coupler.test.php
@@ -45,7 +45,7 @@ function testFind() {
$Model =& ClassRegistry::init('Song');
$Model->Behaviors->attach('Media.Coupler', $this->_behaviorSettings);
$result = $Model->find('all');
- $this->assertEqual(count($result), 3);
+ $this->assertEqual(count($result), 4);
/* Virtual */
$result = $Model->findById(1);

0 comments on commit 2a188ed

Please sign in to comment.