/** * @param string $commaSeparatedExistingModelIds * @throws FailedFileUploadException */ public function actionCloneExistingFiles($commaSeparatedExistingModelIds) { assert('is_string($commaSeparatedExistingModelIds)'); $existingFileModelIds = explode(',', $commaSeparatedExistingModelIds); // Not Coding Standard $newFileModelsData = array(); //needs id, name, size at least, preferably type too. foreach ($existingFileModelIds as $existingFileModelId) { $newFileModel = FileModelUtil::makeByExistingFileModelId($existingFileModelId); if ($newFileModel === false) { throw new FailedFileUploadException(); } $newFileModelsData[] = array('name' => $newFileModel->name, 'type' => $newFileModel->type, 'size' => FileModelDisplayUtil::convertSizeToHumanReadableAndGet($newFileModel->size), 'id' => $newFileModel->id); } $newFileModelsJson = CJSON::encode($newFileModelsData); echo $newFileModelsJson; }
public function testMakeByExistingFileModelId() { Yii::app()->user->userModel = User::getByUsername('super'); $file1 = ZurmoTestHelper::createFileModel(); $file2 = FileModelUtil::makeByExistingFileModelId($file1->id); $this->assertTrue($file2 !== false); $this->assertEquals($file1->fileContent->content, $file2->fileContent->content); $this->assertEquals($file1->name, $file2->name); $this->assertEquals($file1->type, $file2->type); $this->assertEquals($file1->size, $file2->size); }
public function testMakeByExistingFileModelIdWithoutSharedContent() { $oldFileContentsCount = FileContent::getCount(); $file1 = ZurmoTestHelper::createFileModel('testNote.txt'); $file2 = FileModelUtil::makeByExistingFileModelId($file1->id, false); $this->assertTrue($file2 !== false); $this->assertEquals($file1->name, $file2->name); $this->assertEquals($file1->type, $file2->type); $this->assertEquals($file1->size, $file2->size); $this->assertEquals($file1->fileContent->content, $file2->fileContent->content); // fileContent should be replicated as we explicitly passed false to sharedContent $this->assertNotEquals($file1->fileContent->id, $file2->fileContent->id); $this->assertEquals($oldFileContentsCount + 2, FileContent::getCount()); }