diff --git a/_config.php b/_config.php
index 6dae167..32ae9cf 100644
--- a/_config.php
+++ b/_config.php
@@ -1,5 +1,6 @@
register('dms_document_link', array('DMSDocument_Controller', 'dms_link_shortcode_handler'));
-if (!file_exists(BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR)) user_error("DMS directory named incorrectly. Please install the DMS module into a folder named: ".DMS_DIR);
\ No newline at end of file
+DMSDocument_versions::$enable_versions = true;
+
+if (DMSDocument_versions::$enable_versions) {
+ //using the same db relations for the versioned documents, as for the actual documents
+ Config::inst()->update('DMSDocument_versions', 'db', DMSDocument::$db);
+}
+
diff --git a/code/DMSDocument.php b/code/DMSDocument.php
index 15a170a..6b1c062 100755
--- a/code/DMSDocument.php
+++ b/code/DMSDocument.php
@@ -365,7 +365,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
* @return DataList List of Document objects
*/
function getVersions() {
- // TODO: Implement getVersions() method.
+ if (!DMSDocument_versions::$enable_versions) user_error("DMSDocument versions are disabled",E_USER_WARNING);
+ return DMSDocument_versions::get_versions($this);
}
/**
@@ -405,10 +406,22 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
$this->removeAllPages();
+ //get rid of any versions have saved for this DMSDocument, too
+ if (DMSDocument_versions::$enable_versions) {
+ $versions = $this->getVersions();
+ if ($versions->Count() > 0) {
+ foreach($versions as $v) {
+ $v->delete();
+ }
+ }
+ }
+
//delete the dataobject
parent::delete();
}
+
+
/**
* Relate an existing file on the filesystem to the document.
* Copies the file to the new destination, as defined in {@link get_DMS_path()}.
@@ -427,6 +440,12 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
//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);
+ }
+
copy($fromPath, $toPath); //this will overwrite the existing file (if present)
//write the filename of the stored document
@@ -510,6 +529,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
$fields = new FieldList(); //don't use the automatic scaffolding, it is slow and unnecessary here
+ $extraTasks = ''; //additional text to inject into the list of tasks at the bottom of a DMSDocument CMSfield
+ $extraFields = FormField::create('Empty');
+
//get list of shortcode page relations
$relationFinder = new ShortCodeRelationFinder();
$relationList = $relationFinder->getList($this->ID);
@@ -554,7 +576,6 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
$gridFieldConfig
);
-
$referencesGrid = GridField::create(
'References',
_t('DMSDocument.RelatedReferences', 'Related References'),
@@ -562,13 +583,35 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
$gridFieldConfig
);
+ if (DMSDocument_versions::$enable_versions) {
+ $versionsGridFieldConfig = GridFieldConfig::create()->addComponents(
+ new GridFieldToolbarHeader(),
+ new GridFieldSortableHeader(),
+ new GridFieldDataColumns(),
+ new GridFieldPaginator(30)
+ );
+ $versionsGridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(Config::inst()->get('DMSDocument_versions', 'display_fields'))
+ ->setFieldCasting(array('LastChanged'=>"Datetime->Ago"))
+ ->setFieldFormatting(array('FilenameWithoutID'=>'$FilenameWithoutID'));
+
+ $versionsGrid = GridField::create(
+ 'Versions',
+ _t('DMSDocument.Versions', 'Versions'),
+ $this->getVersions(),
+ $versionsGridFieldConfig
+ );
+ $extraTasks .= '