euromark 12 年 前
コミット
6d406b4b7c

+ 4 - 2
Model/Behavior/ResetBehavior.php

@@ -62,7 +62,7 @@ class ResetBehavior extends ModelBehavior {
 	 * @param Model $Model
 	 * @param array $conditions
 	 * @param integer $recursive
-	 * @return boolean Success
+	 * @return integer Modified records
 	 */
 	public function resetRecords(Model $Model, $params = array()) {
 		$recursive = -1;
@@ -104,6 +104,7 @@ class ResetBehavior extends ModelBehavior {
 			set_time_limit(max($max, $count / $limit));
 		}
 
+		$modifed = 0;
 		while ($rows = $Model->find('all', $params)) {
 			foreach ($rows as $row) {
 				$Model->create();
@@ -131,13 +132,14 @@ class ResetBehavior extends ModelBehavior {
 				if (!$res) {
 					throw new CakeException(print_r($Model->validationErrors, true));
 				}
+				$modifed++;
 			}
 			$params['page']++;
 			if ($timeout) {
 				sleep((int)$timeout);
 			}
 		}
-		return true;
+		return $modifed;
 	}
 
 }

+ 7 - 7
Test/Case/Model/Behavior/ResetBehaviorTest.php

@@ -30,7 +30,7 @@ class ResetBehaviorTest extends MyCakeTestCase {
 		$x = $this->Model->find('first', array('order' => array('updated' => 'DESC')));
 
 		$result = $this->Model->resetRecords();
-		$this->assertTrue($result);
+		$this->assertTrue((bool)$result);
 
 		$y = $this->Model->find('first', array('order' => array('updated' => 'DESC')));
 		$this->assertSame($x, $y);
@@ -44,7 +44,7 @@ class ResetBehaviorTest extends MyCakeTestCase {
 		$this->assertTrue($x['MyComment']['updated'] < '2007-12-31');
 
 		$result = $this->Model->resetRecords();
-		$this->assertTrue($result);
+		$this->assertTrue((bool)$result);
 
 		$x = $this->Model->find('first', array('order' => array('updated' => 'ASC')));
 		$this->assertTrue($x['MyComment']['updated'] > (date('Y') - 1) . '-12-31');
@@ -58,7 +58,7 @@ class ResetBehaviorTest extends MyCakeTestCase {
 		$this->assertEquals('Second Comment for Second Article', $x['MyComment']['comment']);
 
 		$result = $this->Model->resetRecords();
-		$this->assertTrue($result);
+		$this->assertTrue((bool)$result);
 
 		$x = $this->Model->find('first', array('conditions' => array('id' => 6)));
 		$expected = 'Second Comment for Second Article xyz';
@@ -73,7 +73,7 @@ class ResetBehaviorTest extends MyCakeTestCase {
 		$this->assertEquals('Second Comment for Second Article', $x['MyComment']['comment']);
 
 		$result = $this->Model->resetRecords();
-		$this->assertTrue($result);
+		$this->assertTrue((bool)$result);
 
 		$x = $this->Model->find('first', array('conditions' => array('id' => 6)));
 		$expected = 'Second Comment for Second Article xxx';
@@ -88,7 +88,7 @@ class ResetBehaviorTest extends MyCakeTestCase {
 		$this->assertEquals('Second Comment for Second Article', $x['MyComment']['comment']);
 
 		$result = $this->Model->resetRecords();
-		$this->assertTrue($result);
+		$this->assertTrue((bool)$result);
 
 		$x = $this->Model->find('first', array('conditions' => array('id' => 6)));
 		$expected = 'Second Comment for Second Article yyy';
@@ -106,7 +106,7 @@ class ResetBehaviorTest extends MyCakeTestCase {
 		$this->assertEquals('Second Comment for Second Article', $x['MyComment']['comment']);
 
 		$result = $this->Model->resetRecords();
-		$this->assertTrue($result);
+		$this->assertTrue((bool)$result);
 
 		$x = $this->Model->find('first', array('conditions' => array('id' => 6)));
 		$expected = 'foo';
@@ -124,7 +124,7 @@ class ResetBehaviorTest extends MyCakeTestCase {
 		$this->assertEquals('Second Comment for Second Article', $x['MyComment']['comment']);
 
 		$result = $this->Model->resetRecords();
-		$this->assertTrue($result);
+		$this->assertTrue((bool)$result);
 
 		$x = $this->Model->find('first', array('conditions' => array('id' => 6)));
 		$expected = 'bar';