function tearDown() { $d = DataObject::get("DMSDocument"); foreach ($d as $d1) { $d1->delete(); } $t = DataObject::get("DMSTag"); foreach ($t as $t1) { $t1->delete(); } //delete the test folder after the test runs $this->delete(BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-versions'); parent::tearDown(); //set the old DMS folder back again DMS::$dmsFolder = self::$dmsFolderOld; DMS::$dmsFolderSize = self::$dmsFolderSizeOld; DMSDocument_versions::$enable_versions = self::$dmsEnableVersionsOld; }
/** * Relate an existing file on the filesystem to the document. * * Copies the file to the new destination, as defined in {@link get_DMS_path()}. * * @param string $filePath Path to file, relative to webroot. * * @return DMSDocument */ public function storeDocument($filePath) { if (empty($this->ID)) { user_error("Document must be written to database before it can store documents", E_USER_ERROR); } // calculate all the path to copy the file to $fromFilename = basename($filePath); $toFilename = $this->ID . '~' . $fromFilename; //add the docID to the start of the Filename $toFolder = DMS::get_storage_folder($this->ID); $toPath = DMS::get_dms_path() . DIRECTORY_SEPARATOR . $toFolder . DIRECTORY_SEPARATOR . $toFilename; DMS::create_storage_folder(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $toFolder); //copy the file into place $fromPath = BASE_PATH . DIRECTORY_SEPARATOR . $filePath; //version the existing file (copy it to a new "very specific" filename if (DMSDocument_versions::$enable_versions) { DMSDocument_versions::create_version($this); } else { //otherwise delete the old document file $oldPath = $this->getFullPath(); if (file_exists($oldPath)) { unlink($oldPath); } } copy($fromPath, $toPath); //this will overwrite the existing file (if present) //write the filename of the stored document $this->Filename = $toFilename; $this->Folder = $toFolder; $extension = pathinfo($this->Filename, PATHINFO_EXTENSION); if (empty($this->Title)) { // don't overwrite existing document titles $this->Title = basename($filePath, '.' . $extension); } $this->LastChanged = SS_Datetime::now()->Rfc2822(); $this->write(); return $this; }
/** * Returns a DataList of all previous Versions of a document (check the * LastEdited date of each object to find the correct one). * * @static * @param DMSDocument $doc * * @return DataList List of Document objects */ static function get_versions(DMSDocument $doc) { if (!DMSDocument_versions::$enable_versions) { user_error("DMSDocument versions are disabled", E_USER_WARNING); } return DMSDocument_versions::get()->filter(array('DocumentID' => $doc->ID)); }