/** * This function updates or inserts the artefact. This involves putting * some data in the artefact table (handled by parent::commit()), and then * some data in the artefact_file_image table. */ public function commit() { // Just forget the whole thing when we're clean. if (empty($this->dirty)) { return; } // We need to keep track of newness before and after. $new = empty($this->id); // Commit to the artefact table. parent::commit(); // Reset dirtyness for the time being. $this->dirty = true; $data = (object) array('artefact' => $this->get('id'), 'width' => $this->get('width'), 'height' => $this->get('height')); if ($new) { insert_record('artefact_file_image', $data); } else { update_record('artefact_file_image', $data, 'artefact'); } $this->dirty = false; }
/** * Test that an artefact gets a new path when moved. */ public function testArtefactHierarchyMove() { // Create folder. $folderdata = array('owner' => $this->testuserid, 'title' => 'Test folder', 'description' => 'Test folder description'); $folder = new ArtefactTypeFolder(0, $folderdata); $folder->commit(); // Create a file. $filedata = array('owner' => $this->testuserid, 'title' => 'Test file', 'description' => 'Test file description'); $file = new ArtefactTypeFile(0, $filedata); $file->commit(); // Check that path is root. $fileid = $file->get('id'); $this->assertEquals('/' . $fileid, $file->get('path')); // "Move" file to a folder. $folderid = $folder->get('id'); $file = new ArtefactTypeFile($fileid); $file->move($folderid); $newpath = "/{$folderid}/{$fileid}"; $this->assertEquals($newpath, $file->get('path')); }