diff --git a/src/AppBundle/Model/Folder.php b/src/AppBundle/Model/Folder.php index 0e4dfa98f..6d67a12b5 100755 --- a/src/AppBundle/Model/Folder.php +++ b/src/AppBundle/Model/Folder.php @@ -51,22 +51,10 @@ class Folder extends BaseItem { public function save(Array $options = array()) { $dirty = $this->getDirty(); - - // Handling of default folder is done in several steps: - // - If changing is_default to false and this is the only default folder - throw an exception. - // - Then save the folder - // - Then, if the folder was set to be the new default, set all the other folders to non-default. - - if (isset($dirty['is_default'])) { - $defaultFolders = self::where('owner_id', '=', $this->owner_id)->where('is_default', '=', 1); - - if (!$dirty['is_default'] && $defaultFolders->count() == 1 && self::defaultFolder($this->owner_id)->id == $this->id) { - throw new \Exception(sprintf('Cannot make folder %s non-default - there should be at least one default folder', BaseModel::hex($this->id))); - } - } - + $output = parent::save($options); + // If the folder was set to be the new default, set all the other folders to non-default. if ($output && isset($dirty['is_default'])) { if (!!$dirty['is_default']) { self::where('owner_id', '=', $this->owner_id)->where('id', '!=', $this->id)->update(array('is_default' => 0)); diff --git a/tests/Model/FolderTest.php b/tests/Model/FolderTest.php index d7537e54c..6c20f5ab5 100644 --- a/tests/Model/FolderTest.php +++ b/tests/Model/FolderTest.php @@ -12,7 +12,7 @@ class FolderTest extends BaseTestCase { Folder::truncate(); } - public function testDefault() { + public function testNewFolderBecomesDefault() { $f1 = new Folder(); $f1->is_default = true; $f1->owner_id = TestUtils::userId(); @@ -29,18 +29,5 @@ class FolderTest extends BaseTestCase { $this->assertTrue(!$f1->is_default); $this->assertTrue(!!$f2->is_default); } - - public function testDefaultException() { - $this->expectException(Exception::class); - - $f1 = new Folder(); - $f1->is_default = true; - $f1->owner_id = TestUtils::userId(); - $f1->save(); - - $f1 = Folder::find($f1->id); - $f1->is_default = false; - $f1->save(); - } } \ No newline at end of file