mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
Converted to PSR-2
This commit is contained in:
parent
1aebe7e8d5
commit
bd707c4ffc
45
code/DMS.php
45
code/DMS.php
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
class DMS implements DMSInterface {
|
||||
class DMS implements DMSInterface
|
||||
{
|
||||
|
||||
static $dmsFolder = 'dms-assets'; //folder to store the documents in
|
||||
public static $dmsFolder = 'dms-assets'; //folder to store the documents in
|
||||
|
||||
//How many documents to store in a single folder. The square of this number is the maximum number of documents.
|
||||
//The number should be a multiple of 10
|
||||
static $dmsFolderSize = 1000;
|
||||
public static $dmsFolderSize = 1000;
|
||||
|
||||
|
||||
/**
|
||||
@ -13,7 +14,8 @@ class DMS implements DMSInterface {
|
||||
* @static
|
||||
* @return DMSInterface An instance of the Document Management System
|
||||
*/
|
||||
static function inst() {
|
||||
public static function inst()
|
||||
{
|
||||
$dmsPath = self::get_dms_path();
|
||||
|
||||
$dms = new DMS();
|
||||
@ -29,17 +31,24 @@ class DMS implements DMSInterface {
|
||||
return $dms;
|
||||
}
|
||||
|
||||
static function get_dms_path() {
|
||||
public static function get_dms_path()
|
||||
{
|
||||
return BASE_PATH . DIRECTORY_SEPARATOR . self::$dmsFolder;
|
||||
}
|
||||
|
||||
static function transform_file_to_file_path($file) {
|
||||
public static function transform_file_to_file_path($file)
|
||||
{
|
||||
//confirm we have a file
|
||||
$filePath = null;
|
||||
if (is_string($file)) $filePath = $file;
|
||||
elseif (is_object($file) && $file->is_a("File")) $filePath = $file->Filename;
|
||||
if (is_string($file)) {
|
||||
$filePath = $file;
|
||||
} elseif (is_object($file) && $file->is_a("File")) {
|
||||
$filePath = $file->Filename;
|
||||
}
|
||||
|
||||
if (!$filePath) throw new FileNotFoundException();
|
||||
if (!$filePath) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
return $filePath;
|
||||
}
|
||||
@ -50,7 +59,8 @@ class DMS implements DMSInterface {
|
||||
* @param $file File object, or String that is path to a file to store, e.g. "assets/documents/industry/supplied-v1-0.pdf"
|
||||
|
||||
*/
|
||||
function storeDocument($file) {
|
||||
public function storeDocument($file)
|
||||
{
|
||||
$filePath = self::transform_file_to_file_path($file);
|
||||
|
||||
//create a new document and get its ID
|
||||
@ -70,7 +80,8 @@ class DMS implements DMSInterface {
|
||||
* @param bool $showEmbargoed Boolean that specifies if embargoed documents should be included in results
|
||||
* @return DocumentInterface
|
||||
*/
|
||||
function getByTag($category = null, $value = null, $showEmbargoed = false) {
|
||||
public function getByTag($category = null, $value = null, $showEmbargoed = false)
|
||||
{
|
||||
// TODO: Implement getByTag() method.
|
||||
}
|
||||
|
||||
@ -81,7 +92,8 @@ class DMS implements DMSInterface {
|
||||
* @param bool $showEmbargoed Boolean that specifies if embargoed documents should be included in results
|
||||
* @return DocumentInterface
|
||||
*/
|
||||
function getByFullTextSearch($searchText, $showEmbargoed = false) {
|
||||
public function getByFullTextSearch($searchText, $showEmbargoed = false)
|
||||
{
|
||||
// TODO: Implement getByFullTextSearch() method.
|
||||
}
|
||||
|
||||
@ -91,7 +103,8 @@ class DMS implements DMSInterface {
|
||||
* @param bool $showEmbargoed Boolean that specifies if embargoed documents should be included in results
|
||||
* @return DataList Document list associated with the Page
|
||||
*/
|
||||
function getByPage($page, $showEmbargoed = false) {
|
||||
public function getByPage($page, $showEmbargoed = false)
|
||||
{
|
||||
// TODO: Implement getByPage() method.
|
||||
}
|
||||
|
||||
@ -99,7 +112,8 @@ class DMS implements DMSInterface {
|
||||
* Creates a storage folder for the given path
|
||||
* @param $path Path to create a folder for
|
||||
*/
|
||||
static function create_storage_folder($path) {
|
||||
public static function create_storage_folder($path)
|
||||
{
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path, 0777);
|
||||
}
|
||||
@ -108,7 +122,8 @@ class DMS implements DMSInterface {
|
||||
/**
|
||||
* Calculates the storage path from a database DMSDocument ID
|
||||
*/
|
||||
static function get_storage_folder($id) {
|
||||
public static function get_storage_folder($id)
|
||||
{
|
||||
$folderName = intval($id / self::$dmsFolderSize);
|
||||
return $folderName;
|
||||
}
|
||||
|
@ -6,21 +6,22 @@
|
||||
*
|
||||
* @package dms
|
||||
*/
|
||||
class DMSShortcodeHandler {
|
||||
class DMSShortcodeHandler
|
||||
{
|
||||
|
||||
public static function handle(
|
||||
$arguments, $content, ShortcodeParser $parser, $tag, array $extra = array()
|
||||
) {
|
||||
if(!empty($arguments['id'])) {
|
||||
if (!empty($arguments['id'])) {
|
||||
$document = DMSDocument::get()->byID($arguments['id']);
|
||||
|
||||
if($document && !$document->isHidden()) {
|
||||
if($content) {
|
||||
if ($document && !$document->isHidden()) {
|
||||
if ($content) {
|
||||
return sprintf(
|
||||
'<a href="%s">%s</a>', $document->Link(), $parser->parse($content)
|
||||
);
|
||||
} else {
|
||||
if(isset($extra['element'])) {
|
||||
if (isset($extra['element'])) {
|
||||
$extra['element']->setAttribute('data-ext', $document->getExtension());
|
||||
$extra['element']->setAttribute('data-size', $document->getFileSizeFormatted());
|
||||
}
|
||||
@ -32,11 +33,10 @@ class DMSShortcodeHandler {
|
||||
|
||||
$error = ErrorPage::get()->filter('ErrorCode', '404')->First();
|
||||
|
||||
if($error) {
|
||||
if ($error) {
|
||||
return $error->Link();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,8 @@
|
||||
* @package dms
|
||||
*/
|
||||
|
||||
class DMSDocumentAddController extends LeftAndMain {
|
||||
class DMSDocumentAddController extends LeftAndMain
|
||||
{
|
||||
|
||||
private static $url_segment = 'pages/adddocument';
|
||||
private static $url_priority = 60;
|
||||
@ -13,9 +14,9 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
private static $tree_class = 'SiteTree';
|
||||
private static $session_namespace = 'CMSMain';
|
||||
|
||||
static $allowed_extensions = array();
|
||||
public static $allowed_extensions = array();
|
||||
|
||||
private static $allowed_actions = array (
|
||||
private static $allowed_actions = array(
|
||||
'getEditForm',
|
||||
'documentautocomplete',
|
||||
'linkdocument',
|
||||
@ -27,10 +28,16 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
* @static
|
||||
* @param $array
|
||||
*/
|
||||
static function add_allowed_extensions($array = null) {
|
||||
if (empty($array)) return;
|
||||
if (is_array($array)) self::$allowed_extensions = $array;
|
||||
else self::$allowed_extensions = array($array);
|
||||
public static function add_allowed_extensions($array = null)
|
||||
{
|
||||
if (empty($array)) {
|
||||
return;
|
||||
}
|
||||
if (is_array($array)) {
|
||||
self::$allowed_extensions = $array;
|
||||
} else {
|
||||
self::$allowed_extensions = array($array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,10 +45,11 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function currentPage() {
|
||||
public function currentPage()
|
||||
{
|
||||
$id = $this->currentPageID();
|
||||
|
||||
if($id && is_numeric($id) && $id > 0) {
|
||||
if ($id && is_numeric($id) && $id > 0) {
|
||||
return Versioned::get_by_stage('SiteTree', 'Stage', sprintf(
|
||||
'ID = %s', (int) $id
|
||||
))->first();
|
||||
@ -54,7 +62,8 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
/**
|
||||
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
|
||||
*/
|
||||
public function currentPageID() {
|
||||
public function currentPageID()
|
||||
{
|
||||
return ($result = parent::currentPageID()) === null ? 0 : $result;
|
||||
}
|
||||
|
||||
@ -62,7 +71,8 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
* @return Form
|
||||
* @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore
|
||||
*/
|
||||
public function getEditForm($id = null, $fields = null) {
|
||||
public function getEditForm($id = null, $fields = null)
|
||||
{
|
||||
Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
|
||||
Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
|
||||
Requirements::css(DMS_DIR.'/css/DMSMainCMS.css');
|
||||
@ -79,7 +89,7 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
$uploadField->setTemplate('AssetUploadField');
|
||||
$uploadField->setRecord($page);
|
||||
|
||||
$uploadField->getValidator()->setAllowedExtensions(array_filter(array_merge(Config::inst()->get('File', 'allowed_extensions'),self::$allowed_extensions)));
|
||||
$uploadField->getValidator()->setAllowedExtensions(array_filter(array_merge(Config::inst()->get('File', 'allowed_extensions'), self::$allowed_extensions)));
|
||||
$exts = $uploadField->getValidator()->getAllowedExtensions();
|
||||
|
||||
asort($exts);
|
||||
@ -139,16 +149,17 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
/**
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function Breadcrumbs($unlinked = false) {
|
||||
public function Breadcrumbs($unlinked = false)
|
||||
{
|
||||
$items = parent::Breadcrumbs($unlinked);
|
||||
|
||||
// The root element should explicitly point to the root node.
|
||||
$items[0]->Link = Controller::join_links(singleton('CMSPageEditController')->Link('show'), 0);
|
||||
|
||||
// Enforce linkage of hierarchy to AssetAdmin
|
||||
foreach($items as $item) {
|
||||
foreach ($items as $item) {
|
||||
$baselink = $this->Link('show');
|
||||
if(strpos($item->Link, $baselink) !== false) {
|
||||
if (strpos($item->Link, $baselink) !== false) {
|
||||
$item->Link = str_replace($baselink, singleton('CMSPageEditController')->Link('show'), $item->Link);
|
||||
}
|
||||
}
|
||||
@ -161,12 +172,14 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function Backlink(){
|
||||
public function Backlink()
|
||||
{
|
||||
$pageID = $this->currentPageID();
|
||||
return singleton('CMSPagesController')->Link().'edit/show/'.$pageID;
|
||||
}
|
||||
|
||||
public function documentautocomplete() {
|
||||
public function documentautocomplete()
|
||||
{
|
||||
$term = (isset($_GET['term'])) ? $_GET['term'] : '';
|
||||
$term_sql = Convert::raw2sql($term);
|
||||
$data = DMSDocument::get()
|
||||
@ -175,7 +188,7 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
->limit(20);
|
||||
|
||||
$return = array();
|
||||
foreach($data as $doc) {
|
||||
foreach ($data as $doc) {
|
||||
$return[] = array(
|
||||
'label' => $doc->ID . ' - ' . $doc->Title,
|
||||
'value' => $doc->ID
|
||||
@ -186,7 +199,8 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function linkdocument() {
|
||||
public function linkdocument()
|
||||
{
|
||||
$return = array('error' => _t('UploadField.FIELDNOTSET', 'Could not add document to page'));
|
||||
|
||||
$page = $this->currentPage();
|
||||
@ -212,17 +226,18 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function documentlist() {
|
||||
if(!isset($_GET['pageID'])) {
|
||||
public function documentlist()
|
||||
{
|
||||
if (!isset($_GET['pageID'])) {
|
||||
return $this->httpError(400);
|
||||
}
|
||||
|
||||
$page = SiteTree::get()->byId($_GET['pageID']);
|
||||
|
||||
if($page && $page->Documents()->count() > 0) {
|
||||
if ($page && $page->Documents()->count() > 0) {
|
||||
$list = '<ul>';
|
||||
|
||||
foreach($page->Documents() as $document) {
|
||||
foreach ($page->Documents() as $document) {
|
||||
$list .= sprintf(
|
||||
'<li><a class="add-document" data-document-id="%s">%s</a></li>',
|
||||
$document->ID,
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
class DMSDocumentAddExistingField extends CompositeField {
|
||||
class DMSDocumentAddExistingField extends CompositeField
|
||||
{
|
||||
|
||||
public $useFieldContext = true;
|
||||
|
||||
function __construct($name, $title = null) {
|
||||
public function __construct($name, $title = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->title = ($title === null) ? $name : $title;
|
||||
|
||||
@ -15,7 +17,8 @@ class DMSDocumentAddExistingField extends CompositeField {
|
||||
* Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File)
|
||||
* @param DataObject $record
|
||||
*/
|
||||
public function setRecord($record) {
|
||||
public function setRecord($record)
|
||||
{
|
||||
$this->record = $record;
|
||||
return $this;
|
||||
}
|
||||
@ -23,7 +26,8 @@ class DMSDocumentAddExistingField extends CompositeField {
|
||||
* Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will use Form->getRecord() or Form->Controller()->data()
|
||||
* @return DataObject
|
||||
*/
|
||||
public function getRecord() {
|
||||
public function getRecord()
|
||||
{
|
||||
if (!$this->record && $this->form) {
|
||||
if ($this->form->getRecord() && is_a($this->form->getRecord(), 'DataObject')) {
|
||||
$this->record = $this->form->getRecord();
|
||||
@ -35,11 +39,13 @@ class DMSDocumentAddExistingField extends CompositeField {
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
public function FieldHolder($properties = array()) {
|
||||
public function FieldHolder($properties = array())
|
||||
{
|
||||
return $this->Field($properties);
|
||||
}
|
||||
|
||||
public function Field($properties = array()) {
|
||||
public function Field($properties = array())
|
||||
{
|
||||
Requirements::javascript(DMS_DIR.'/javascript/DMSDocumentAddExistingField.js');
|
||||
Requirements::javascript(DMS_DIR."/javascript/DocumentHtmlEditorFieldToolbar.js");
|
||||
|
||||
@ -50,7 +56,8 @@ class DMSDocumentAddExistingField extends CompositeField {
|
||||
* Sets or unsets the use of the "field" class in the template. The "field" class adds Javascript behaviour
|
||||
* that causes unwelcome hiding side-effects when this Field is used within the link editor pop-up
|
||||
*/
|
||||
public function setUseFieldClass($use = false) {
|
||||
public function setUseFieldClass($use = false)
|
||||
{
|
||||
$this->useFieldContext = $use;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,8 @@
|
||||
* @package dms
|
||||
* @subpackage cms
|
||||
*/
|
||||
class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridField_ColumnProvider, GridField_ActionProvider {
|
||||
class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridField_ColumnProvider, GridField_ActionProvider
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
@ -22,21 +23,22 @@ class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridFiel
|
||||
* @param string $columnName
|
||||
* @return string - the HTML for the column
|
||||
*/
|
||||
public function getColumnContent($gridField, $record, $columnName) {
|
||||
if($this->removeRelation) {
|
||||
public function getColumnContent($gridField, $record, $columnName)
|
||||
{
|
||||
if ($this->removeRelation) {
|
||||
$field = GridField_FormAction::create($gridField, 'UnlinkRelation'.$record->ID, false, "unlinkrelation", array('RecordID' => $record->ID))
|
||||
->addExtraClass('gridfield-button-unlink')
|
||||
->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink"))
|
||||
->setAttribute('data-icon', 'chain--minus');
|
||||
} else {
|
||||
if(!$record->canDelete()) {
|
||||
if (!$record->canDelete()) {
|
||||
return;
|
||||
}
|
||||
$field = GridField_FormAction::create($gridField, 'DeleteRecord'.$record->ID, false, "deleterecord", array('RecordID' => $record->ID))
|
||||
->addExtraClass('gridfield-button-delete')
|
||||
->setAttribute('title', _t('GridAction.Delete', "Delete"))
|
||||
->setAttribute('data-icon', 'cross-circle')
|
||||
->setDescription(_t('GridAction.DELETE_DESCRIPTION','Delete'));
|
||||
->setDescription(_t('GridAction.DELETE_DESCRIPTION', 'Delete'));
|
||||
}
|
||||
|
||||
//add a class to the field to if it is the last gridfield in the list
|
||||
@ -46,8 +48,11 @@ class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridFiel
|
||||
->removeExtraClass('gridfield-button-delete'); //remove the base gridfield behaviour
|
||||
|
||||
//set a class telling JS what kind of warning to display when clicking the delete button
|
||||
if ($numberOfRelations > 1) $field->addExtraClass('dms-delete-link-only');
|
||||
else $field->addExtraClass('dms-delete-last-warning');
|
||||
if ($numberOfRelations > 1) {
|
||||
$field->addExtraClass('dms-delete-link-only');
|
||||
} else {
|
||||
$field->addExtraClass('dms-delete-last-warning');
|
||||
}
|
||||
|
||||
//set a class to show if the document is hidden
|
||||
if ($record->isHidden()) {
|
||||
@ -66,21 +71,26 @@ class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridFiel
|
||||
* @param array $data - form data
|
||||
* @return void
|
||||
*/
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
||||
if($actionName == 'deleterecord' || $actionName == 'unlinkrelation') {
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||
{
|
||||
if ($actionName == 'deleterecord' || $actionName == 'unlinkrelation') {
|
||||
$item = $gridField->getList()->byID($arguments['RecordID']);
|
||||
if(!$item) {
|
||||
if (!$item) {
|
||||
return;
|
||||
}
|
||||
if($actionName == 'deleterecord' && !$item->canDelete()) {
|
||||
throw new ValidationException(_t('GridFieldAction_Delete.DeletePermissionsFailure',"No delete permissions"),0);
|
||||
if ($actionName == 'deleterecord' && !$item->canDelete()) {
|
||||
throw new ValidationException(_t('GridFieldAction_Delete.DeletePermissionsFailure', "No delete permissions"), 0);
|
||||
}
|
||||
|
||||
$delete = false;
|
||||
if ($item->Pages()->Count() <= 1) $delete = true;
|
||||
if ($item->Pages()->Count() <= 1) {
|
||||
$delete = true;
|
||||
}
|
||||
|
||||
$gridField->getList()->remove($item); //remove the relation
|
||||
if ($delete) $item->delete(); //delete the DMSDocument
|
||||
if ($delete) {
|
||||
$item->delete();
|
||||
} //delete the DMSDocument
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@
|
||||
/**
|
||||
* Custom ItemRequest class the provides custom delete behaviour for the CMSFields of DMSDocument
|
||||
*/
|
||||
class DMSGridFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest {
|
||||
class DMSGridFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
|
||||
{
|
||||
private static $allowed_actions = array('ItemEditForm');
|
||||
|
||||
function ItemEditForm() {
|
||||
public function ItemEditForm()
|
||||
{
|
||||
$form = parent::ItemEditForm();
|
||||
|
||||
//add a data attribute specifying how many pages this document is referenced on
|
||||
@ -21,5 +23,4 @@ class DMSGridFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,14 +12,16 @@
|
||||
* @author Julian Seidenberg
|
||||
* @package dms
|
||||
*/
|
||||
class DMSUploadField extends UploadField {
|
||||
private static $allowed_actions = array (
|
||||
class DMSUploadField extends UploadField
|
||||
{
|
||||
private static $allowed_actions = array(
|
||||
"upload",
|
||||
);
|
||||
|
||||
protected $folderName = 'DMSTemporaryUploads';
|
||||
|
||||
public function __construct($name, $title = null, SS_List $items = null) {
|
||||
public function __construct($name, $title = null, SS_List $items = null)
|
||||
{
|
||||
parent::__construct($name, $title, $items);
|
||||
|
||||
//set default DMS replace template to false
|
||||
@ -32,11 +34,12 @@ class DMSUploadField extends UploadField {
|
||||
* add it into the DMS storage, deleting the old/uploaded file.
|
||||
* @param File
|
||||
*/
|
||||
protected function attachFile($file) {
|
||||
protected function attachFile($file)
|
||||
{
|
||||
$dms = DMS::inst();
|
||||
$record = $this->getRecord();
|
||||
|
||||
if($record instanceof DMSDocument) {
|
||||
if ($record instanceof DMSDocument) {
|
||||
// If the edited record is a document,
|
||||
// assume we're replacing an existing file
|
||||
$doc = $record;
|
||||
@ -53,16 +56,19 @@ class DMSUploadField extends UploadField {
|
||||
return $doc;
|
||||
}
|
||||
|
||||
public function validate($validator) {
|
||||
public function validate($validator)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function isDisabled() {
|
||||
public function isDisabled()
|
||||
{
|
||||
return (parent::isDisabled() || !$this->isSaveable());
|
||||
}
|
||||
|
||||
public function isSaveable() {
|
||||
public function isSaveable()
|
||||
{
|
||||
return (!empty($this->getRecord()->ID));
|
||||
}
|
||||
|
||||
@ -72,12 +78,17 @@ class DMSUploadField extends UploadField {
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return string json
|
||||
*/
|
||||
public function upload(SS_HTTPRequest $request) {
|
||||
if($this->isDisabled() || $this->isReadonly()) return $this->httpError(403);
|
||||
public function upload(SS_HTTPRequest $request)
|
||||
{
|
||||
if ($this->isDisabled() || $this->isReadonly()) {
|
||||
return $this->httpError(403);
|
||||
}
|
||||
|
||||
// Protect against CSRF on destructive action
|
||||
$token = $this->getForm()->getSecurityToken();
|
||||
if(!$token->checkRequest($request)) return $this->httpError(400);
|
||||
if (!$token->checkRequest($request)) {
|
||||
return $this->httpError(400);
|
||||
}
|
||||
|
||||
$name = $this->getName();
|
||||
$tmpfile = $request->postVar($name);
|
||||
@ -100,16 +111,20 @@ class DMSUploadField extends UploadField {
|
||||
$tooManyFiles = false;
|
||||
// Some relationships allow many files to be attached.
|
||||
if ($this->getConfig('allowedMaxFileNumber') && ($record->has_many($name) || $record->many_many($name))) {
|
||||
if(!$record->isInDB()) $record->write();
|
||||
if (!$record->isInDB()) {
|
||||
$record->write();
|
||||
}
|
||||
$tooManyFiles = $record->{$name}()->count() >= $this->getConfig('allowedMaxFileNumber');
|
||||
// has_one only allows one file at any given time.
|
||||
} elseif($record->has_one($name)) {
|
||||
} elseif ($record->has_one($name)) {
|
||||
$tooManyFiles = $record->{$name}() && $record->{$name}()->exists();
|
||||
}
|
||||
|
||||
// Report the constraint violation.
|
||||
if ($tooManyFiles) {
|
||||
if(!$this->getConfig('allowedMaxFileNumber')) $this->setConfig('allowedMaxFileNumber', 1);
|
||||
if (!$this->getConfig('allowedMaxFileNumber')) {
|
||||
$this->setConfig('allowedMaxFileNumber', 1);
|
||||
}
|
||||
$return['error'] = _t(
|
||||
'UploadField.MAXNUMBEROFFILES',
|
||||
'Max number of {count} file(s) exceeded.',
|
||||
@ -172,11 +187,13 @@ class DMSUploadField extends UploadField {
|
||||
* Never directly display items uploaded
|
||||
* @return SS_List
|
||||
*/
|
||||
public function getItems() {
|
||||
public function getItems()
|
||||
{
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
public function Field($properties = array()) {
|
||||
public function Field($properties = array())
|
||||
{
|
||||
$fields = parent::Field($properties);
|
||||
|
||||
// Replace the download template with a new one only when access the upload field through a GridField.
|
||||
@ -193,14 +210,16 @@ class DMSUploadField extends UploadField {
|
||||
* @param int $itemID
|
||||
* @return UploadField_ItemHandler
|
||||
*/
|
||||
public function getItemHandler($itemID) {
|
||||
public function getItemHandler($itemID)
|
||||
{
|
||||
return DMSUploadField_ItemHandler::create($this, $itemID);
|
||||
}
|
||||
}
|
||||
|
||||
class DMSUploadField_ItemHandler extends UploadField_ItemHandler {
|
||||
function getItem() {
|
||||
class DMSUploadField_ItemHandler extends UploadField_ItemHandler
|
||||
{
|
||||
public function getItem()
|
||||
{
|
||||
return DataObject::get_by_id('DMSDocument', $this->itemID);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,16 +4,20 @@
|
||||
*/
|
||||
|
||||
|
||||
class DocumentHtmlEditorFieldToolbar extends Extension {
|
||||
class DocumentHtmlEditorFieldToolbar extends Extension
|
||||
{
|
||||
|
||||
function updateLinkForm(Form $form) {
|
||||
public function updateLinkForm(Form $form)
|
||||
{
|
||||
$linkType = null;
|
||||
$fieldList = null;
|
||||
$fields = $form->Fields();//->fieldByName('Heading');
|
||||
foreach($fields as $field) {
|
||||
foreach ($fields as $field) {
|
||||
$linkType = ($field->fieldByName('LinkType'));
|
||||
$fieldList = $field;
|
||||
if ($linkType) break; //break once we have the object
|
||||
if ($linkType) {
|
||||
break;
|
||||
} //break once we have the object
|
||||
}
|
||||
|
||||
$source = $linkType->getSource();
|
||||
@ -23,7 +27,7 @@ class DocumentHtmlEditorFieldToolbar extends Extension {
|
||||
$addExistingField = new DMSDocumentAddExistingField('AddExisting', 'Add Existing');
|
||||
$addExistingField->setForm($form);
|
||||
$addExistingField->setUseFieldClass(false);
|
||||
$fieldList->insertAfter($addExistingField,'Description');
|
||||
$fieldList->insertAfter($addExistingField, 'Description');
|
||||
|
||||
// Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
|
||||
// Requirements::javascript(SAPPHIRE_DIR . "/javascript/tiny_mce_improvements.js");
|
||||
|
@ -3,6 +3,6 @@
|
||||
* Simple exception extension so that we can tell the difference between internally
|
||||
* raised exceptions and those thrown by DMS.
|
||||
*/
|
||||
class FileNotFoundException extends Exception {
|
||||
|
||||
class FileNotFoundException extends Exception
|
||||
{
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* @package dms
|
||||
*/
|
||||
class DMSSiteTreeExtension extends DataExtension {
|
||||
class DMSSiteTreeExtension extends DataExtension
|
||||
{
|
||||
|
||||
private static $belongs_many_many = array(
|
||||
'Documents' => 'DMSDocument'
|
||||
@ -18,8 +19,11 @@ class DMSSiteTreeExtension extends DataExtension {
|
||||
* @static
|
||||
* @param $mixed Array of page types to not show the Documents tab on
|
||||
*/
|
||||
static function no_documents_tab($array = array()) {
|
||||
if (empty($array)) return;
|
||||
public static function no_documents_tab($array = array())
|
||||
{
|
||||
if (empty($array)) {
|
||||
return;
|
||||
}
|
||||
if (is_array($array)) {
|
||||
self::$noDocumentsList = $array;
|
||||
} else {
|
||||
@ -33,8 +37,11 @@ class DMSSiteTreeExtension extends DataExtension {
|
||||
* @static
|
||||
* @param $array Array of page types to show the Documents tab on
|
||||
*/
|
||||
static function show_documents_tab($array = array()) {
|
||||
if (empty($array)) return;
|
||||
public static function show_documents_tab($array = array())
|
||||
{
|
||||
if (empty($array)) {
|
||||
return;
|
||||
}
|
||||
if (is_array($array)) {
|
||||
self::$showDocumentsList = $array;
|
||||
} else {
|
||||
@ -42,10 +49,15 @@ class DMSSiteTreeExtension extends DataExtension {
|
||||
}
|
||||
}
|
||||
|
||||
function updateCMSFields(FieldList $fields){
|
||||
public function updateCMSFields(FieldList $fields)
|
||||
{
|
||||
//prevent certain pages from having a Document tab in the CMS
|
||||
if (in_array($this->owner->ClassName,self::$noDocumentsList)) return;
|
||||
if (count(self::$showDocumentsList) > 0 && !in_array($this->owner->ClassName,self::$showDocumentsList)) return;
|
||||
if (in_array($this->owner->ClassName, self::$noDocumentsList)) {
|
||||
return;
|
||||
}
|
||||
if (count(self::$showDocumentsList) > 0 && !in_array($this->owner->ClassName, self::$showDocumentsList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//javascript to customize the grid field for the DMS document (overriding entwine in FRAMEWORK_DIR.'/javascript/GridField.js'
|
||||
Requirements::javascript(DMS_DIR.'/javascript/DMSGridField.js');
|
||||
@ -67,17 +79,17 @@ class DMSSiteTreeExtension extends DataExtension {
|
||||
//GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')
|
||||
);
|
||||
|
||||
if(class_exists('GridFieldPaginatorWithShowAll')){
|
||||
if (class_exists('GridFieldPaginatorWithShowAll')) {
|
||||
$paginatorComponent = new GridFieldPaginatorWithShowAll(15);
|
||||
}else{
|
||||
} else {
|
||||
$paginatorComponent = new GridFieldPaginator(15);
|
||||
}
|
||||
$gridFieldConfig->addComponent($paginatorComponent);
|
||||
|
||||
if(class_exists('GridFieldSortableRows')) {
|
||||
if (class_exists('GridFieldSortableRows')) {
|
||||
$sortableComponent = new GridFieldSortableRows('DocumentSort');
|
||||
//setUsePagenation method removed from newer version of SortableGridField.
|
||||
if(method_exists($sortableComponent,'setUsePagination')){
|
||||
if (method_exists($sortableComponent, 'setUsePagination')) {
|
||||
$sortableComponent->setUsePagination(false)->setForceRedraw(true);
|
||||
}
|
||||
$gridFieldConfig->addComponent($sortableComponent);
|
||||
@ -121,21 +133,23 @@ class DMSSiteTreeExtension extends DataExtension {
|
||||
/**
|
||||
* Enforce sorting for frontend
|
||||
*/
|
||||
function PageDocuments() {
|
||||
public function PageDocuments()
|
||||
{
|
||||
return $this->owner->getManyManyComponents('Documents')->sort('DocumentSort');
|
||||
}
|
||||
|
||||
function onBeforeDelete() {
|
||||
if(Versioned::current_stage() == 'Live') {
|
||||
public function onBeforeDelete()
|
||||
{
|
||||
if (Versioned::current_stage() == 'Live') {
|
||||
$existsOnOtherStage = !$this->owner->getIsDeletedFromStage();
|
||||
} else {
|
||||
$existsOnOtherStage = $this->owner->getExistsOnLive();
|
||||
}
|
||||
|
||||
// Only remove if record doesn't still exist on live stage.
|
||||
if(!$existsOnOtherStage) {
|
||||
if (!$existsOnOtherStage) {
|
||||
$dmsDocuments = $this->owner->Documents();
|
||||
foreach($dmsDocuments as $document) {
|
||||
foreach ($dmsDocuments as $document) {
|
||||
//if the document is only associated with one page, i.e. only associated with this page
|
||||
if ($document->Pages()->Count() <= 1) {
|
||||
//delete the document before deleting this page
|
||||
@ -145,18 +159,19 @@ class DMSSiteTreeExtension extends DataExtension {
|
||||
}
|
||||
}
|
||||
|
||||
function onBeforePublish() {
|
||||
$embargoedDocuments = $this->owner->Documents()->filter('EmbargoedUntilPublished',true);
|
||||
public function onBeforePublish()
|
||||
{
|
||||
$embargoedDocuments = $this->owner->Documents()->filter('EmbargoedUntilPublished', true);
|
||||
if ($embargoedDocuments->Count() > 0) {
|
||||
foreach($embargoedDocuments as $doc) {
|
||||
foreach ($embargoedDocuments as $doc) {
|
||||
$doc->EmbargoedUntilPublished = false;
|
||||
$doc->write();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getTitleWithNumberOfDocuments() {
|
||||
public function getTitleWithNumberOfDocuments()
|
||||
{
|
||||
return $this->owner->Title . ' (' . $this->owner->Documents()->Count() . ')';
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@
|
||||
* instance of the DMSInterface. All write operations on the DMSDocument create a new relation, so we never need to
|
||||
* explicitly call the write() method on the DMSDocument DataObject
|
||||
*/
|
||||
interface DMSDocumentInterface {
|
||||
interface DMSDocumentInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Deletes the DMSDocument, its underlying file, as well as any tags related to this DMSDocument.
|
||||
@ -23,7 +24,7 @@ interface DMSDocumentInterface {
|
||||
* @param $pageObject Page object to associate this DMSDocument with
|
||||
* @return null
|
||||
*/
|
||||
function addPage($pageObject);
|
||||
public function addPage($pageObject);
|
||||
|
||||
/**
|
||||
* Associates this DMSDocument with a set of Pages. This method loops through a set of page ids, and then associates this
|
||||
@ -32,7 +33,7 @@ interface DMSDocumentInterface {
|
||||
* @param $pageIDs array of page ids used for the page objects associate this DMSDocument with
|
||||
* @return null
|
||||
*/
|
||||
function addPages($pageIDs);
|
||||
public function addPages($pageIDs);
|
||||
|
||||
/**
|
||||
* Removes the association between this DMSDocument and a Page. This method does nothing if the association does not exist.
|
||||
@ -40,21 +41,21 @@ interface DMSDocumentInterface {
|
||||
* @param $pageObject Page object to remove the association to
|
||||
* @return mixed
|
||||
*/
|
||||
function removePage($pageObject);
|
||||
public function removePage($pageObject);
|
||||
|
||||
/**
|
||||
* Returns a list of the Page objects associated with this DMSDocument
|
||||
* @abstract
|
||||
* @return DataList
|
||||
*/
|
||||
function getPages();
|
||||
public function getPages();
|
||||
|
||||
/**
|
||||
* Removes all associated Pages from the DMSDocument
|
||||
* @abstract
|
||||
* @return null
|
||||
*/
|
||||
function removeAllPages();
|
||||
public function removeAllPages();
|
||||
|
||||
/**
|
||||
* Adds a metadata tag to the DMSDocument. The tag has a category and a value.
|
||||
@ -69,7 +70,7 @@ interface DMSDocumentInterface {
|
||||
* @param bool $multiValue Boolean that determines if the category is multi-value or single-value (optional)
|
||||
* @return null
|
||||
*/
|
||||
function addTag($category, $value, $multiValue = true);
|
||||
public function addTag($category, $value, $multiValue = true);
|
||||
|
||||
/**
|
||||
* Fetches all tags associated with this DMSDocument within a given category. If a value is specified this method
|
||||
@ -79,7 +80,7 @@ interface DMSDocumentInterface {
|
||||
* @param null $value String of the value of the tag to get
|
||||
* @return array of Strings of all the tags or null if there is no match found
|
||||
*/
|
||||
function getTagsList($category, $value = null);
|
||||
public function getTagsList($category, $value = null);
|
||||
|
||||
/**
|
||||
* Removes a tag from the DMSDocument. If you only set a category, then all values in that category are deleted.
|
||||
@ -90,40 +91,40 @@ interface DMSDocumentInterface {
|
||||
* @param null $value Value to remove (optional)
|
||||
* @return null
|
||||
*/
|
||||
function removeTag($category, $value = null);
|
||||
public function removeTag($category, $value = null);
|
||||
|
||||
/**
|
||||
* Deletes all tags associated with this DMSDocument.
|
||||
* @abstract
|
||||
* @return null
|
||||
*/
|
||||
function removeAllTags();
|
||||
public function removeAllTags();
|
||||
|
||||
/**
|
||||
* Returns a link to download this DMSDocument from the DMS store
|
||||
* @abstract
|
||||
* @return String
|
||||
*/
|
||||
function getLink();
|
||||
public function getLink();
|
||||
|
||||
/**
|
||||
* Return the extension of the file associated with the document
|
||||
*/
|
||||
function getExtension();
|
||||
public function getExtension();
|
||||
|
||||
/**
|
||||
* Returns the size of the file type in an appropriate format.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getSize();
|
||||
public function getSize();
|
||||
|
||||
/**
|
||||
* Return the size of the file associated with the document, in bytes.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getAbsoluteSize();
|
||||
public function getAbsoluteSize();
|
||||
|
||||
|
||||
/**
|
||||
@ -132,7 +133,7 @@ interface DMSDocumentInterface {
|
||||
* @param $file File object, or String that is path to a file to store
|
||||
* @return DMSDocumentInstance Document object that we replaced the file in
|
||||
*/
|
||||
function replaceDocument($file);
|
||||
public function replaceDocument($file);
|
||||
|
||||
/**
|
||||
* Hides the DMSDocument, so it does not show up when getByPage($myPage) is called
|
||||
@ -141,14 +142,14 @@ interface DMSDocumentInterface {
|
||||
* @abstract
|
||||
* @return null
|
||||
*/
|
||||
function embargoIndefinitely();
|
||||
public function embargoIndefinitely();
|
||||
|
||||
/**
|
||||
* Returns if this is DMSDocument is embargoed or expired.
|
||||
* @abstract
|
||||
* @return bool True or False depending on whether this DMSDocument is embargoed or expired
|
||||
*/
|
||||
function isHidden();
|
||||
public function isHidden();
|
||||
|
||||
|
||||
/**
|
||||
@ -156,7 +157,7 @@ interface DMSDocumentInterface {
|
||||
* @abstract
|
||||
* @return bool True or False depending on whether this DMSDocument is embargoed
|
||||
*/
|
||||
function isEmbargoed();
|
||||
public function isEmbargoed();
|
||||
|
||||
/**
|
||||
* Hides the DMSDocument, so it does not show up when getByPage($myPage) is called. Automatically un-hides the
|
||||
@ -165,27 +166,27 @@ interface DMSDocumentInterface {
|
||||
* @param $datetime String date time value when this DMSDocument should expire
|
||||
* @return null
|
||||
*/
|
||||
function embargoUntilDate($datetime);
|
||||
public function embargoUntilDate($datetime);
|
||||
|
||||
/**
|
||||
* Hides the document until any page it is linked to is published
|
||||
* @return null
|
||||
*/
|
||||
function embargoUntilPublished();
|
||||
public function embargoUntilPublished();
|
||||
|
||||
/**
|
||||
* Clears any previously set embargos, so the DMSDocument always shows up in all queries.
|
||||
* @abstract
|
||||
* @return null
|
||||
*/
|
||||
function clearEmbargo();
|
||||
public function clearEmbargo();
|
||||
|
||||
/**
|
||||
* Returns if this is DMSDocument is expired.
|
||||
* @abstract
|
||||
* @return bool True or False depending on whether this DMSDocument is expired
|
||||
*/
|
||||
function isExpired();
|
||||
public function isExpired();
|
||||
|
||||
/**
|
||||
* Hides the DMSDocument at a specific date, so it does not show up when getByPage($myPage) is called.
|
||||
@ -193,14 +194,14 @@ interface DMSDocumentInterface {
|
||||
* @param $datetime String date time value when this DMSDocument should expire
|
||||
* @return null
|
||||
*/
|
||||
function expireAtDate($datetime);
|
||||
public function expireAtDate($datetime);
|
||||
|
||||
/**
|
||||
* Clears any previously set expiry.
|
||||
* @abstract
|
||||
* @return null
|
||||
*/
|
||||
function clearExpiry();
|
||||
public function clearExpiry();
|
||||
|
||||
/*---- FROM HERE ON: optional API features ----*/
|
||||
|
||||
@ -210,6 +211,5 @@ interface DMSDocumentInterface {
|
||||
* @abstract
|
||||
* @return DataList List of DMSDocument objects
|
||||
*/
|
||||
function getVersions();
|
||||
|
||||
public function getVersions();
|
||||
}
|
@ -8,7 +8,8 @@
|
||||
* 10000 files per folder is a good amount)
|
||||
*
|
||||
*/
|
||||
interface DMSInterface {
|
||||
interface DMSInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Factory method that returns an instance of the DMS. This could be any class that implements the DMSInterface.
|
||||
@ -16,7 +17,7 @@ interface DMSInterface {
|
||||
* @abstract
|
||||
* @return DMSInterface An instance of the Document Management System
|
||||
*/
|
||||
static function inst();
|
||||
public static function inst();
|
||||
|
||||
/**
|
||||
* Takes a File object or a String (path to a file) and copies it into the DMS. The original file remains unchanged.
|
||||
@ -25,7 +26,7 @@ interface DMSInterface {
|
||||
* @param $file File object, or String that is path to a file to store
|
||||
* @return DMSDocumentInstance Document object that we just created
|
||||
*/
|
||||
function storeDocument($file);
|
||||
public function storeDocument($file);
|
||||
|
||||
/**
|
||||
*
|
||||
@ -37,7 +38,7 @@ interface DMSInterface {
|
||||
* @param bool $showEmbargoed Boolean that specifies if embargoed documents should be included in results
|
||||
* @return DMSDocumentInterface
|
||||
*/
|
||||
function getByTag($category = null, $value = null, $showEmbargoed = false);
|
||||
public function getByTag($category = null, $value = null, $showEmbargoed = false);
|
||||
|
||||
/**
|
||||
* Returns a number of Document objects that match a full-text search of the Documents and their contents
|
||||
@ -47,7 +48,7 @@ interface DMSInterface {
|
||||
* @param bool $showEmbargoed Boolean that specifies if embargoed documents should be included in results
|
||||
* @return DMSDocumentInterface
|
||||
*/
|
||||
function getByFullTextSearch($searchText, $showEmbargoed = false);
|
||||
public function getByFullTextSearch($searchText, $showEmbargoed = false);
|
||||
|
||||
|
||||
/**
|
||||
@ -57,5 +58,5 @@ interface DMSInterface {
|
||||
* @param bool $showEmbargoed Boolean that specifies if embargoed documents should be included in results
|
||||
* @return DataList Document list associated with the Page
|
||||
*/
|
||||
function getByPage($page, $showEmbargoed = false);
|
||||
public function getByPage($page, $showEmbargoed = false);
|
||||
}
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* @package dms
|
||||
*/
|
||||
class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
class DMSDocument extends DataObject implements DMSDocumentInterface
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
"Filename" => "Varchar(255)", // eg. 3469~2011-energysaving-report.pdf
|
||||
@ -56,19 +57,22 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
if (!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
|
||||
$member = Member::currentUser();
|
||||
}
|
||||
|
||||
// extended access checks
|
||||
$results = $this->extend('canView', $member);
|
||||
|
||||
if($results && is_array($results)) {
|
||||
if(!min($results)) return false;
|
||||
if ($results && is_array($results)) {
|
||||
if (!min($results)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if($member && $member->ID){
|
||||
if ($member && $member->ID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -80,15 +84,18 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
if (!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
|
||||
$member = Member::currentUser();
|
||||
}
|
||||
|
||||
$results = $this->extend('canEdit', $member);
|
||||
|
||||
if($results && is_array($results)) {
|
||||
if(!min($results)) return false;
|
||||
if ($results && is_array($results)) {
|
||||
if (!min($results)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->canView();
|
||||
@ -99,15 +106,18 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
if (!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
|
||||
$member = Member::currentUser();
|
||||
}
|
||||
|
||||
$results = $this->extend('canCreate', $member);
|
||||
|
||||
if($results && is_array($results)) {
|
||||
if(!min($results)) return false;
|
||||
if ($results && is_array($results)) {
|
||||
if (!min($results)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->canView();
|
||||
@ -118,15 +128,18 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
if (!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
|
||||
$member = Member::currentUser();
|
||||
}
|
||||
|
||||
$results = $this->extend('canDelete', $member);
|
||||
|
||||
if($results && is_array($results)) {
|
||||
if(!min($results)) return false;
|
||||
if ($results && is_array($results)) {
|
||||
if (!min($results)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->canView();
|
||||
@ -146,7 +159,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function addPage($pageObject) {
|
||||
public function addPage($pageObject)
|
||||
{
|
||||
$this->Pages()->add($pageObject);
|
||||
|
||||
DB::query("UPDATE \"DMSDocument_Pages\" SET \"DocumentSort\"=\"DocumentSort\"+1 WHERE \"SiteTreeID\" = $pageObject->ID");
|
||||
@ -163,11 +177,12 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function addPages($pageIDs) {
|
||||
foreach($pageIDs as $id) {
|
||||
public function addPages($pageIDs)
|
||||
{
|
||||
foreach ($pageIDs as $id) {
|
||||
$pageObject = DataObject::get_by_id("SiteTree", $id);
|
||||
|
||||
if($pageObject && $pageObject->exists()) {
|
||||
if ($pageObject && $pageObject->exists()) {
|
||||
$this->addPage($pageObject);
|
||||
}
|
||||
}
|
||||
@ -183,7 +198,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function removePage($pageObject) {
|
||||
public function removePage($pageObject)
|
||||
{
|
||||
$this->Pages()->remove($pageObject);
|
||||
|
||||
return $this;
|
||||
@ -194,7 +210,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DataList
|
||||
*/
|
||||
public function Pages() {
|
||||
public function Pages()
|
||||
{
|
||||
$pages = $this->getManyManyComponents('Pages');
|
||||
$this->extend('updatePages', $pages);
|
||||
|
||||
@ -206,7 +223,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DataList
|
||||
*/
|
||||
public function getPages() {
|
||||
public function getPages()
|
||||
{
|
||||
return $this->Pages();
|
||||
}
|
||||
|
||||
@ -215,7 +233,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function removeAllPages() {
|
||||
public function removeAllPages()
|
||||
{
|
||||
$this->Pages()->removeAll();
|
||||
|
||||
return $this;
|
||||
@ -227,7 +246,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function trackView() {
|
||||
public function trackView()
|
||||
{
|
||||
if ($this->ID > 0) {
|
||||
$count = $this->ViewCount + 1;
|
||||
|
||||
@ -261,7 +281,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function addTag($category, $value, $multiValue = true) {
|
||||
public function addTag($category, $value, $multiValue = true)
|
||||
{
|
||||
if ($multiValue) {
|
||||
//check for a duplicate tag, don't add the duplicate
|
||||
$currentTag = $this->Tags()->filter(array('Category' => $category, 'Value' => $value));
|
||||
@ -275,7 +296,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
$tag->Documents()->add($this);
|
||||
} else {
|
||||
//add the relation between the tag and document
|
||||
foreach($currentTag as $tagObj) {
|
||||
foreach ($currentTag as $tagObj) {
|
||||
$tagObj->Documents()->add($this);
|
||||
}
|
||||
}
|
||||
@ -312,9 +333,12 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DataList
|
||||
*/
|
||||
protected function getTagsObjects($category, $value = null) {
|
||||
protected function getTagsObjects($category, $value = null)
|
||||
{
|
||||
$valueFilter = array("Category" => $category);
|
||||
if (!empty($value)) $valueFilter['Value'] = $value;
|
||||
if (!empty($value)) {
|
||||
$valueFilter['Value'] = $value;
|
||||
}
|
||||
|
||||
$tags = $this->Tags()->filter($valueFilter);
|
||||
return $tags;
|
||||
@ -330,7 +354,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return array Strings of all the tags or null if there is no match found
|
||||
*/
|
||||
public function getTagsList($category, $value = null) {
|
||||
public function getTagsList($category, $value = null)
|
||||
{
|
||||
$tags = $this->getTagsObjects($category, $value);
|
||||
|
||||
$returnArray = null;
|
||||
@ -338,7 +363,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
if ($tags->Count() > 0) {
|
||||
$returnArray = array();
|
||||
|
||||
foreach($tags as $t) {
|
||||
foreach ($tags as $t) {
|
||||
$returnArray[] = $t->Value;
|
||||
}
|
||||
}
|
||||
@ -360,18 +385,21 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function removeTag($category, $value = null) {
|
||||
public function removeTag($category, $value = null)
|
||||
{
|
||||
$tags = $this->getTagsObjects($category, $value);
|
||||
|
||||
if ($tags->Count() > 0) {
|
||||
foreach($tags as $t) {
|
||||
foreach ($tags as $t) {
|
||||
$documentList = $t->Documents();
|
||||
|
||||
//remove the relation between the tag and the document
|
||||
$documentList->remove($this);
|
||||
|
||||
//delete the entire tag if it has no relations left
|
||||
if ($documentList->Count() == 0) $t->delete();
|
||||
if ($documentList->Count() == 0) {
|
||||
$t->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,13 +411,16 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function removeAllTags() {
|
||||
public function removeAllTags()
|
||||
{
|
||||
$allTags = $this->Tags();
|
||||
|
||||
foreach($allTags as $tag) {
|
||||
foreach ($allTags as $tag) {
|
||||
$documentlist = $tag->Documents();
|
||||
$documentlist->remove($this);
|
||||
if ($tag->Documents()->Count() == 0) $tag->delete();
|
||||
if ($tag->Documents()->Count() == 0) {
|
||||
$tag->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -400,14 +431,16 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLink() {
|
||||
return Controller::join_links(Director::baseURL(),'dmsdocument/'.$this->ID);
|
||||
public function getLink()
|
||||
{
|
||||
return Controller::join_links(Director::baseURL(), 'dmsdocument/'.$this->ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function Link() {
|
||||
public function Link()
|
||||
{
|
||||
return $this->getLink();
|
||||
}
|
||||
|
||||
@ -422,10 +455,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function embargoIndefinitely($write = true) {
|
||||
public function embargoIndefinitely($write = true)
|
||||
{
|
||||
$this->EmbargoedIndefinitely = true;
|
||||
|
||||
if ($write) $this->write();
|
||||
if ($write) {
|
||||
$this->write();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -437,10 +473,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function embargoUntilPublished($write = true) {
|
||||
public function embargoUntilPublished($write = true)
|
||||
{
|
||||
$this->EmbargoedUntilPublished = true;
|
||||
|
||||
if ($write) $this->write();
|
||||
if ($write) {
|
||||
$this->write();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -456,12 +495,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden() {
|
||||
public function isHidden()
|
||||
{
|
||||
$hidden = $this->isEmbargoed() || $this->isExpired();
|
||||
$readingMode = Versioned::get_reading_mode();
|
||||
|
||||
if ($readingMode == "Stage.Stage") {
|
||||
if($this->EmbargoedUntilPublished == true) {
|
||||
if ($this->EmbargoedUntilPublished == true) {
|
||||
$hidden = false;
|
||||
}
|
||||
}
|
||||
@ -474,7 +514,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmbargoed() {
|
||||
public function isEmbargoed()
|
||||
{
|
||||
if (is_object($this->EmbargoedUntilDate)) {
|
||||
$this->EmbargoedUntilDate = $this->EmbargoedUntilDate->Value;
|
||||
}
|
||||
@ -483,10 +524,10 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
|
||||
if ($this->EmbargoedIndefinitely) {
|
||||
$embargoed = true;
|
||||
} else if ($this->EmbargoedUntilPublished) {
|
||||
} elseif ($this->EmbargoedUntilPublished) {
|
||||
$embargoed = true;
|
||||
} else if (!empty($this->EmbargoedUntilDate)) {
|
||||
if(SS_Datetime::now()->Value < $this->EmbargoedUntilDate) {
|
||||
} elseif (!empty($this->EmbargoedUntilDate)) {
|
||||
if (SS_Datetime::now()->Value < $this->EmbargoedUntilDate) {
|
||||
$embargoed = true;
|
||||
}
|
||||
}
|
||||
@ -503,10 +544,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function embargoUntilDate($datetime, $write = true) {
|
||||
public function embargoUntilDate($datetime, $write = true)
|
||||
{
|
||||
$this->EmbargoedUntilDate = DBField::create_field('SS_Datetime', $datetime)->Format('Y-m-d H:i:s');
|
||||
|
||||
if ($write) $this->write();
|
||||
if ($write) {
|
||||
$this->write();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -519,12 +563,15 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function clearEmbargo($write = true) {
|
||||
public function clearEmbargo($write = true)
|
||||
{
|
||||
$this->EmbargoedIndefinitely = false;
|
||||
$this->EmbargoedUntilPublished = false;
|
||||
$this->EmbargoedUntilDate = null;
|
||||
|
||||
if ($write) $this->write();
|
||||
if ($write) {
|
||||
$this->write();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -534,7 +581,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired() {
|
||||
public function isExpired()
|
||||
{
|
||||
if (is_object($this->ExpireAtDate)) {
|
||||
$this->ExpireAtDate = $this->ExpireAtDate->Value;
|
||||
}
|
||||
@ -542,7 +590,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
$expired = false;
|
||||
|
||||
if (!empty($this->ExpireAtDate)) {
|
||||
if(SS_Datetime::now()->Value >= $this->ExpireAtDate) {
|
||||
if (SS_Datetime::now()->Value >= $this->ExpireAtDate) {
|
||||
$expired = true;
|
||||
}
|
||||
}
|
||||
@ -559,10 +607,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function expireAtDate($datetime, $write = true) {
|
||||
public function expireAtDate($datetime, $write = true)
|
||||
{
|
||||
$this->ExpireAtDate = DBField::create_field('SS_Datetime', $datetime)->Format('Y-m-d H:i:s');
|
||||
|
||||
if ($write) $this->write();
|
||||
if ($write) {
|
||||
$this->write();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -574,10 +625,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function clearExpiry($write = true) {
|
||||
public function clearExpiry($write = true)
|
||||
{
|
||||
$this->ExpireAtDate = null;
|
||||
|
||||
if ($write) $this->write();
|
||||
if ($write) {
|
||||
$this->write();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -593,7 +647,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DataList List of Document objects
|
||||
*/
|
||||
public function getVersions() {
|
||||
public function getVersions()
|
||||
{
|
||||
if (!DMSDocument_versions::$enable_versions) {
|
||||
throw new Exception("DMSDocument versions are disabled");
|
||||
}
|
||||
@ -606,8 +661,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFullPath() {
|
||||
if($this->Filename) {
|
||||
public function getFullPath()
|
||||
{
|
||||
if ($this->Filename) {
|
||||
return DMS::get_dms_path() . DIRECTORY_SEPARATOR . $this->Folder . DIRECTORY_SEPARATOR . $this->Filename;
|
||||
}
|
||||
|
||||
@ -619,8 +675,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName() {
|
||||
if($this->getField('Filename')) {
|
||||
public function getFileName()
|
||||
{
|
||||
if ($this->getField('Filename')) {
|
||||
return $this->getField('Filename');
|
||||
} else {
|
||||
return ASSETS_DIR . '/';
|
||||
@ -630,7 +687,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName() {
|
||||
public function getName()
|
||||
{
|
||||
return $this->getField('Title');
|
||||
}
|
||||
|
||||
@ -638,8 +696,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFilenameWithoutID() {
|
||||
$filenameParts = explode('~',$this->Filename);
|
||||
public function getFilenameWithoutID()
|
||||
{
|
||||
$filenameParts = explode('~', $this->Filename);
|
||||
$filename = array_pop($filenameParts);
|
||||
|
||||
return $filename;
|
||||
@ -648,7 +707,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStorageFolder() {
|
||||
public function getStorageFolder()
|
||||
{
|
||||
return DMS::get_dms_path() . DIRECTORY_SEPARATOR . DMS::get_storage_folder($this->ID);
|
||||
}
|
||||
|
||||
@ -659,7 +719,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete() {
|
||||
public function delete()
|
||||
{
|
||||
// remove tags
|
||||
$this->removeAllTags();
|
||||
|
||||
@ -671,7 +732,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
if ($handle = opendir($storageFolder)) {
|
||||
while (false !== ($entry = readdir($handle))) {
|
||||
// only delete if filename starts the the relevant ID
|
||||
if(strpos($entry,$this->ID.'~') === 0) {
|
||||
if (strpos($entry, $this->ID.'~') === 0) {
|
||||
$filesToDelete[] = $entry;
|
||||
}
|
||||
}
|
||||
@ -679,7 +740,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
closedir($handle);
|
||||
|
||||
//delete all this files that have the id of this document
|
||||
foreach($filesToDelete as $file) {
|
||||
foreach ($filesToDelete as $file) {
|
||||
$filePath = $storageFolder .DIRECTORY_SEPARATOR . $file;
|
||||
|
||||
if (is_file($filePath)) {
|
||||
@ -696,7 +757,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
$versions = $this->getVersions();
|
||||
|
||||
if ($versions->Count() > 0) {
|
||||
foreach($versions as $v) {
|
||||
foreach ($versions as $v) {
|
||||
$v->delete();
|
||||
}
|
||||
}
|
||||
@ -716,7 +777,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function storeDocument($filePath) {
|
||||
public function storeDocument($filePath)
|
||||
{
|
||||
if (empty($this->ID)) {
|
||||
user_error("Document must be written to database before it can store documents", E_USER_ERROR);
|
||||
}
|
||||
@ -737,7 +799,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
DMSDocument_versions::create_version($this);
|
||||
} else { //otherwise delete the old document file
|
||||
$oldPath = $this->getFullPath();
|
||||
if (file_exists($oldPath)) unlink($oldPath);
|
||||
if (file_exists($oldPath)) {
|
||||
unlink($oldPath);
|
||||
}
|
||||
}
|
||||
|
||||
copy($fromPath, $toPath); //this will overwrite the existing file (if present)
|
||||
@ -750,7 +814,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
|
||||
if (empty($this->Title)) {
|
||||
// don't overwrite existing document titles
|
||||
$this->Title = basename($filePath,'.'.$extension);
|
||||
$this->Title = basename($filePath, '.'.$extension);
|
||||
}
|
||||
|
||||
$this->LastChanged = SS_Datetime::now()->Rfc2822();
|
||||
@ -768,7 +832,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument object that we replaced the file in
|
||||
*/
|
||||
public function replaceDocument($file) {
|
||||
public function replaceDocument($file)
|
||||
{
|
||||
$filePath = DMS::transform_file_to_file_path($file);
|
||||
$doc = $this->storeDocument($filePath); // replace the document
|
||||
|
||||
@ -784,7 +849,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_file_type($ext) {
|
||||
public static function get_file_type($ext)
|
||||
{
|
||||
$types = array(
|
||||
'gif' => 'GIF image - good for diagrams',
|
||||
'jpg' => 'JPEG image - good for photos',
|
||||
@ -819,14 +885,16 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescriptionWithLineBreak() {
|
||||
public function getDescriptionWithLineBreak()
|
||||
{
|
||||
return nl2br($this->getField('Description'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
//include JS to handling showing and hiding of bottom "action" tabs
|
||||
Requirements::javascript(DMS_DIR.'/javascript/DMSDocumentCMSFields.js');
|
||||
Requirements::css(DMS_DIR.'/css/DMSDocumentCMSFields.css');
|
||||
@ -843,8 +911,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
$fieldsTop = $this->getFieldsForFile($relationList->count());
|
||||
$fields->add($fieldsTop);
|
||||
|
||||
$fields->add(new TextField('Title','Title'));
|
||||
$fields->add(new TextareaField('Description','Description'));
|
||||
$fields->add(new TextField('Title', 'Title'));
|
||||
$fields->add(new TextareaField('Description', 'Description'));
|
||||
|
||||
//create upload field to replace document
|
||||
$uploadField = new DMSUploadField('ReplaceFile', 'Replace file');
|
||||
@ -920,17 +988,23 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
'</ul></div>'));
|
||||
|
||||
$embargoValue = 'None';
|
||||
if ($this->EmbargoedIndefinitely) $embargoValue = 'Indefinitely';
|
||||
elseif ($this->EmbargoedUntilPublished) $embargoValue = 'Published';
|
||||
elseif (!empty($this->EmbargoedUntilDate)) $embargoValue = 'Date';
|
||||
$embargo = new OptionsetField('Embargo','Embargo',array('None'=>'None','Published'=>'Hide document until page is published','Indefinitely'=>'Hide document indefinitely','Date'=>'Hide until set date'),$embargoValue);
|
||||
$embargoDatetime = DatetimeField::create('EmbargoedUntilDate','');
|
||||
if ($this->EmbargoedIndefinitely) {
|
||||
$embargoValue = 'Indefinitely';
|
||||
} elseif ($this->EmbargoedUntilPublished) {
|
||||
$embargoValue = 'Published';
|
||||
} elseif (!empty($this->EmbargoedUntilDate)) {
|
||||
$embargoValue = 'Date';
|
||||
}
|
||||
$embargo = new OptionsetField('Embargo', 'Embargo', array('None'=>'None', 'Published'=>'Hide document until page is published', 'Indefinitely'=>'Hide document indefinitely', 'Date'=>'Hide until set date'), $embargoValue);
|
||||
$embargoDatetime = DatetimeField::create('EmbargoedUntilDate', '');
|
||||
$embargoDatetime->getDateField()->setConfig('showcalendar', true)->setConfig('dateformat', 'dd-MM-yyyy')->setConfig('datavalueformat', 'dd-MM-yyyy');
|
||||
|
||||
$expiryValue = 'None';
|
||||
if (!empty($this->ExpireAtDate)) $expiryValue = 'Date';
|
||||
$expiry = new OptionsetField('Expiry','Expiry',array('None'=>'None','Date'=>'Set document to expire on'),$expiryValue);
|
||||
$expiryDatetime = DatetimeField::create('ExpireAtDate','');
|
||||
if (!empty($this->ExpireAtDate)) {
|
||||
$expiryValue = 'Date';
|
||||
}
|
||||
$expiry = new OptionsetField('Expiry', 'Expiry', array('None'=>'None', 'Date'=>'Set document to expire on'), $expiryValue);
|
||||
$expiryDatetime = DatetimeField::create('ExpireAtDate', '');
|
||||
$expiryDatetime->getDateField()->setConfig('showcalendar', true)->setConfig('dateformat', 'dd-MM-yyyy')->setConfig('datavalueformat', 'dd-MM-yyyy');
|
||||
|
||||
// This adds all the actions details into a group.
|
||||
@ -993,7 +1067,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function onBeforeWrite() {
|
||||
public function onBeforeWrite()
|
||||
{
|
||||
parent::onBeforeWrite();
|
||||
|
||||
if (isset($this->Embargo)) {
|
||||
@ -1002,14 +1077,23 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
$savedDate = $this->EmbargoedUntilDate;
|
||||
$this->clearEmbargo(false); //clear all previous settings and re-apply them on save
|
||||
|
||||
if ($this->Embargo == 'Published') $this->embargoUntilPublished(false);
|
||||
if ($this->Embargo == 'Indefinitely') $this->embargoIndefinitely(false);
|
||||
if ($this->Embargo == 'Date') $this->embargoUntilDate($savedDate, false);
|
||||
if ($this->Embargo == 'Published') {
|
||||
$this->embargoUntilPublished(false);
|
||||
}
|
||||
if ($this->Embargo == 'Indefinitely') {
|
||||
$this->embargoIndefinitely(false);
|
||||
}
|
||||
if ($this->Embargo == 'Date') {
|
||||
$this->embargoUntilDate($savedDate, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->Expiry)) {
|
||||
if ($this->Expiry == 'Date') $this->expireAtDate($this->ExpireAtDate, false);
|
||||
else $this->clearExpiry(false); //clear all previous settings
|
||||
if ($this->Expiry == 'Date') {
|
||||
$this->expireAtDate($this->ExpireAtDate, false);
|
||||
} else {
|
||||
$this->clearExpiry(false);
|
||||
} //clear all previous settings
|
||||
}
|
||||
}
|
||||
|
||||
@ -1021,12 +1105,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function Icon($ext) {
|
||||
if(!Director::fileExists(DMS_DIR."/images/app_icons/{$ext}_32.png")) {
|
||||
public function Icon($ext)
|
||||
{
|
||||
if (!Director::fileExists(DMS_DIR."/images/app_icons/{$ext}_32.png")) {
|
||||
$ext = File::get_app_category($ext);
|
||||
}
|
||||
|
||||
if(!Director::fileExists(DMS_DIR."/images/app_icons/{$ext}_32.png")) {
|
||||
if (!Director::fileExists(DMS_DIR."/images/app_icons/{$ext}_32.png")) {
|
||||
$ext = "generic";
|
||||
}
|
||||
|
||||
@ -1038,14 +1123,16 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExtension() {
|
||||
public function getExtension()
|
||||
{
|
||||
return strtolower(pathinfo($this->Filename, PATHINFO_EXTENSION));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSize() {
|
||||
public function getSize()
|
||||
{
|
||||
$size = $this->getAbsoluteSize();
|
||||
return ($size) ? File::format_size($size) : false;
|
||||
}
|
||||
@ -1055,7 +1142,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAbsoluteSize() {
|
||||
public function getAbsoluteSize()
|
||||
{
|
||||
return file_exists($this->getFullPath()) ? filesize($this->getFullPath()) : null;
|
||||
}
|
||||
|
||||
@ -1064,7 +1152,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileSizeFormatted() {
|
||||
public function getFileSizeFormatted()
|
||||
{
|
||||
return $this->getSize();
|
||||
}
|
||||
|
||||
@ -1072,20 +1161,25 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
protected function getFieldsForFile($relationListCount) {
|
||||
protected function getFieldsForFile($relationListCount)
|
||||
{
|
||||
$extension = $this->getExtension();
|
||||
|
||||
$previewField = new LiteralField("ImageFull",
|
||||
"<img id='thumbnailImage' class='thumbnail-preview' src='{$this->Icon($extension)}?r=" . rand(1,100000) . "' alt='{$this->Title}' />\n"
|
||||
"<img id='thumbnailImage' class='thumbnail-preview' src='{$this->Icon($extension)}?r=" . rand(1, 100000) . "' alt='{$this->Title}' />\n"
|
||||
);
|
||||
|
||||
//count the number of pages this document is published on
|
||||
$publishedOnCount = $this->Pages()->Count();
|
||||
$publishedOnValue = "$publishedOnCount pages";
|
||||
if ($publishedOnCount == 1) $publishedOnValue = "$publishedOnCount page";
|
||||
if ($publishedOnCount == 1) {
|
||||
$publishedOnValue = "$publishedOnCount page";
|
||||
}
|
||||
|
||||
$relationListCountValue = "$relationListCount pages";
|
||||
if ($relationListCount == 1) $relationListCountValue = "$relationListCount page";
|
||||
if ($relationListCount == 1) {
|
||||
$relationListCountValue = "$relationListCount page";
|
||||
}
|
||||
|
||||
$fields = new FieldGroup(
|
||||
$filePreview = CompositeField::create(
|
||||
@ -1095,15 +1189,15 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
CompositeField::create(
|
||||
CompositeField::create(
|
||||
new ReadonlyField("ID", "ID number". ':', $this->ID),
|
||||
new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':', self::get_file_type($extension)),
|
||||
new ReadonlyField("Size", _t('AssetTableField.SIZE','File size') . ':', $this->getFileSizeFormatted()),
|
||||
$urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL','URL'),
|
||||
new ReadonlyField("FileType", _t('AssetTableField.TYPE', 'File type') . ':', self::get_file_type($extension)),
|
||||
new ReadonlyField("Size", _t('AssetTableField.SIZE', 'File size') . ':', $this->getFileSizeFormatted()),
|
||||
$urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL', 'URL'),
|
||||
sprintf('<a href="%s" target="_blank" class="file-url">%s</a>', $this->getLink(), $this->getLink())
|
||||
),
|
||||
new ReadonlyField("FilenameWithoutIDField", "Filename". ':', $this->getFilenameWithoutID()),
|
||||
new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded') . ':', $this->Created),
|
||||
new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed') . ':', $this->LastEdited),
|
||||
new DateField_Disabled("LastChanged", _t('AssetTableField.LASTCHANGED','Last replaced') . ':', $this->LastChanged),
|
||||
new DateField_Disabled("Created", _t('AssetTableField.CREATED', 'First uploaded') . ':', $this->Created),
|
||||
new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT', 'Last changed') . ':', $this->LastEdited),
|
||||
new DateField_Disabled("LastChanged", _t('AssetTableField.LASTCHANGED', 'Last replaced') . ':', $this->LastChanged),
|
||||
new ReadonlyField("PublishedOn", "Published on". ':', $publishedOnValue),
|
||||
new ReadonlyField("ReferencedOn", "Referenced on". ':', $relationListCountValue),
|
||||
new ReadonlyField("ViewCount", "View count". ':', $this->ViewCount)
|
||||
@ -1126,27 +1220,29 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
*
|
||||
* @return DMSDocument
|
||||
*/
|
||||
public function ingestFile($file) {
|
||||
public function ingestFile($file)
|
||||
{
|
||||
$this->replaceDocument($file);
|
||||
$file->delete();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package dms
|
||||
*/
|
||||
class DMSDocument_Controller extends Controller {
|
||||
class DMSDocument_Controller extends Controller
|
||||
{
|
||||
|
||||
static $testMode = false; //mode to switch for testing. Does not return document download, just document URL
|
||||
public static $testMode = false; //mode to switch for testing. Does not return document download, just document URL
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'index'
|
||||
);
|
||||
|
||||
public function init() {
|
||||
public function init()
|
||||
{
|
||||
Versioned::choose_site_stage();
|
||||
parent::init();
|
||||
}
|
||||
@ -1155,13 +1251,14 @@ class DMSDocument_Controller extends Controller {
|
||||
* Returns the document object from the request object's ID parameter.
|
||||
* Returns null, if no document found
|
||||
*/
|
||||
protected function getDocumentFromID($request) {
|
||||
protected function getDocumentFromID($request)
|
||||
{
|
||||
$doc = null;
|
||||
|
||||
$id = Convert::raw2sql($request->param('ID'));
|
||||
|
||||
if (strpos($id, 'version') === 0) { //versioned document
|
||||
$id = str_replace('version','',$id);
|
||||
$id = str_replace('version', '', $id);
|
||||
$doc = DataObject::get_by_id('DMSDocument_versions', $id);
|
||||
$this->extend('updateVersionFromID', $doc, $request);
|
||||
} else { //normal document
|
||||
@ -1176,7 +1273,8 @@ class DMSDocument_Controller extends Controller {
|
||||
* Access the file download without redirecting user, so we can block direct
|
||||
* access to documents.
|
||||
*/
|
||||
public function index(SS_HTTPRequest $request) {
|
||||
public function index(SS_HTTPRequest $request)
|
||||
{
|
||||
$doc = $this->getDocumentFromID($request);
|
||||
|
||||
if (!empty($doc)) {
|
||||
@ -1187,7 +1285,7 @@ class DMSDocument_Controller extends Controller {
|
||||
if (method_exists($doc, 'Pages')) {
|
||||
$pages = $doc->Pages();
|
||||
if ($pages->Count() > 0) {
|
||||
foreach($pages as $page) {
|
||||
foreach ($pages as $page) {
|
||||
if ($page->CanView()) {
|
||||
// just one canView is enough to know that we can
|
||||
// view the file
|
||||
@ -1203,40 +1301,44 @@ class DMSDocument_Controller extends Controller {
|
||||
}
|
||||
|
||||
// check for embargo or expiry
|
||||
if ($doc->isHidden()) $canView = false;
|
||||
if ($doc->isHidden()) {
|
||||
$canView = false;
|
||||
}
|
||||
|
||||
//admins can always download any document, even if otherwise hidden
|
||||
$member = Member::currentUser();
|
||||
if ($member && Permission::checkMember($member, 'ADMIN')) $canView = true;
|
||||
if ($member && Permission::checkMember($member, 'ADMIN')) {
|
||||
$canView = true;
|
||||
}
|
||||
|
||||
if ($canView) {
|
||||
$path = $doc->getFullPath();
|
||||
if ( is_file($path) ) {
|
||||
if (is_file($path)) {
|
||||
$fileBin = trim(`whereis file`);
|
||||
if ( function_exists('finfo_file') ) {
|
||||
if (function_exists('finfo_file')) {
|
||||
// discover the mime type properly
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
$mime = finfo_file($finfo, $path);
|
||||
}
|
||||
else if ( is_executable($fileBin) ) {
|
||||
} elseif (is_executable($fileBin)) {
|
||||
// try to use the system tool
|
||||
$mime = `$fileBin -i -b $path`;
|
||||
$mime = explode(';', $mime);
|
||||
$mime = trim($mime[0]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// make do with what we have
|
||||
$ext = $doc->getExtension();
|
||||
if ( $ext =='pdf') {
|
||||
if ($ext =='pdf') {
|
||||
$mime = 'application/pdf';
|
||||
}elseif ($ext == 'html' || $ext =='htm') {
|
||||
} elseif ($ext == 'html' || $ext =='htm') {
|
||||
$mime = 'text/html';
|
||||
}else {
|
||||
} else {
|
||||
$mime = 'application/octet-stream';
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$testMode) return $path;
|
||||
if (self::$testMode) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
//if a DMSDocument can be downloaded and all the permissions/privileges has passed,
|
||||
//its ViewCount should be increased by 1 just before the browser sending the file to front.
|
||||
@ -1244,7 +1346,9 @@ class DMSDocument_Controller extends Controller {
|
||||
|
||||
header('Content-Type: ' . $mime);
|
||||
header('Content-Length: ' . filesize($path), null);
|
||||
if (!empty($mime) && $mime != "text/html") header('Content-Disposition: attachment; filename="'.$doc->getFilenameWithoutID().'"');
|
||||
if (!empty($mime) && $mime != "text/html") {
|
||||
header('Content-Disposition: attachment; filename="'.$doc->getFilenameWithoutID().'"');
|
||||
}
|
||||
header('Content-transfer-encoding: 8bit');
|
||||
header('Expires: 0');
|
||||
header('Pragma: cache');
|
||||
@ -1256,7 +1360,9 @@ class DMSDocument_Controller extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$testMode) return 'This asset does not exist.';
|
||||
if (self::$testMode) {
|
||||
return 'This asset does not exist.';
|
||||
}
|
||||
$this->httpError(404, 'This asset does not exist.');
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,8 @@
|
||||
*
|
||||
* @package dms
|
||||
*/
|
||||
class DMSDocument_versions extends DataObject {
|
||||
class DMSDocument_versions extends DataObject
|
||||
{
|
||||
|
||||
/**
|
||||
* @var bool $enable_versions Flag that turns on or off versions of
|
||||
@ -62,7 +63,8 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @return bool Success or failure
|
||||
*/
|
||||
public static function create_version(DMSDocument $doc) {
|
||||
public static function create_version(DMSDocument $doc)
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$existingPath = $doc->getFullPath();
|
||||
@ -72,7 +74,7 @@ class DMSDocument_versions extends DataObject {
|
||||
$version = new DMSDocument_versions($docData); //create a copy of the current DMSDocument as a version
|
||||
|
||||
$previousVersionCounter = 0;
|
||||
$newestExistingVersion = self::get_versions($doc)->sort(array('Created'=>'DESC','ID'=>'DESC'))->limit(1);
|
||||
$newestExistingVersion = self::get_versions($doc)->sort(array('Created'=>'DESC', 'ID'=>'DESC'))->limit(1);
|
||||
if ($newestExistingVersion && $newestExistingVersion->Count() > 0) {
|
||||
$previousVersionCounter = $newestExistingVersion->first()->VersionCounter;
|
||||
}
|
||||
@ -95,10 +97,13 @@ class DMSDocument_versions extends DataObject {
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
public function delete()
|
||||
{
|
||||
$path = $this->getFullPath();
|
||||
|
||||
if (file_exists($path)) unlink($path);
|
||||
if (file_exists($path)) {
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
@ -112,15 +117,19 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @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);
|
||||
public 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));
|
||||
}
|
||||
|
||||
public function __construct($record = null, $isSingleton = false, $model = null) {
|
||||
public function __construct($record = null, $isSingleton = false, $model = null)
|
||||
{
|
||||
//check what the constructor was passed
|
||||
$dmsObject = null;
|
||||
if ($record && is_subclass_of($record,'DMSDocumentInterface')) {
|
||||
if ($record && is_subclass_of($record, 'DMSDocumentInterface')) {
|
||||
$dmsObject = $record;
|
||||
$record = null; //cancel the record creation to just create an empty object
|
||||
}
|
||||
@ -130,7 +139,7 @@ class DMSDocument_versions extends DataObject {
|
||||
|
||||
//copy the DMSDocument object, if passed into the constructor
|
||||
if ($dmsObject) {
|
||||
foreach(array_keys(DataObject::custom_database_fields($dmsObject->ClassName)) as $key) {
|
||||
foreach (array_keys(DataObject::custom_database_fields($dmsObject->ClassName)) as $key) {
|
||||
$this->$key = $dmsObject->$key;
|
||||
}
|
||||
}
|
||||
@ -141,8 +150,9 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLink() {
|
||||
return Controller::join_links(Director::baseURL(),'dmsdocument/version'.$this->ID);
|
||||
public function getLink()
|
||||
{
|
||||
return Controller::join_links(Director::baseURL(), 'dmsdocument/version'.$this->ID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,7 +161,8 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden() {
|
||||
public function isHidden()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -163,16 +174,20 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFullPath($filename = null) {
|
||||
if (!$filename) $filename = $this->Filename;
|
||||
public function getFullPath($filename = null)
|
||||
{
|
||||
if (!$filename) {
|
||||
$filename = $this->Filename;
|
||||
}
|
||||
return DMS::get_dms_path() . DIRECTORY_SEPARATOR . $this->Folder . DIRECTORY_SEPARATOR . $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFilenameWithoutID() {
|
||||
$filenameParts = explode('~',$this->Filename);
|
||||
public function getFilenameWithoutID()
|
||||
{
|
||||
$filenameParts = explode('~', $this->Filename);
|
||||
$filename = array_pop($filenameParts);
|
||||
|
||||
return $filename;
|
||||
@ -186,19 +201,20 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @return string The new filename
|
||||
*/
|
||||
protected function generateVersionedFilename(DMSDocument $doc, $versionCounter) {
|
||||
protected function generateVersionedFilename(DMSDocument $doc, $versionCounter)
|
||||
{
|
||||
$filename = $doc->Filename;
|
||||
|
||||
do {
|
||||
$versionPaddingString = str_pad($versionCounter, 4, '0', STR_PAD_LEFT); //add leading zeros to make sorting accurate up to 10,000 documents
|
||||
$newVersionFilename = preg_replace('/([0-9]+~)(.*?)/','$1~'.$versionPaddingString.'~$2',$filename);
|
||||
$newVersionFilename = preg_replace('/([0-9]+~)(.*?)/', '$1~'.$versionPaddingString.'~$2', $filename);
|
||||
|
||||
if ($newVersionFilename == $filename || empty($newVersionFilename)) { //sanity check for crazy document names
|
||||
user_error('Cannot generate new document filename for file: '.$filename,E_USER_ERROR);
|
||||
user_error('Cannot generate new document filename for file: '.$filename, E_USER_ERROR);
|
||||
}
|
||||
|
||||
$versionCounter++; //increase the counter for the next loop run, if necessary
|
||||
} while(file_exists($this->getFullPath($newVersionFilename)));
|
||||
} while (file_exists($this->getFullPath($newVersionFilename)));
|
||||
|
||||
return $newVersionFilename;
|
||||
}
|
||||
@ -208,14 +224,16 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExtension() {
|
||||
public function getExtension()
|
||||
{
|
||||
return strtolower(pathinfo($this->Filename, PATHINFO_EXTENSION));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSize() {
|
||||
public function getSize()
|
||||
{
|
||||
$size = $this->getAbsoluteSize();
|
||||
|
||||
return ($size) ? File::format_size($size) : false;
|
||||
@ -226,7 +244,8 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAbsoluteSize() {
|
||||
public function getAbsoluteSize()
|
||||
{
|
||||
return filesize($this->getFullPath());
|
||||
}
|
||||
|
||||
@ -235,14 +254,16 @@ class DMSDocument_versions extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileSizeFormatted() {
|
||||
public function getFileSizeFormatted()
|
||||
{
|
||||
return $this->getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DMSDocument_versions
|
||||
*/
|
||||
public function trackView() {
|
||||
public function trackView()
|
||||
{
|
||||
if ($this->ID > 0) {
|
||||
$this->VersionViewCount++;
|
||||
|
||||
@ -253,5 +274,4 @@ class DMSDocument_versions extends DataObject {
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,8 @@
|
||||
*
|
||||
* @package dms
|
||||
*/
|
||||
class DMSTag extends DataObject {
|
||||
class DMSTag extends DataObject
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'Category' => 'Varchar(1024)',
|
||||
|
@ -9,7 +9,8 @@
|
||||
* search across dozens of columns and tables - but for a couple of hundred pages
|
||||
* and occasionally use its a feasible solution.
|
||||
*/
|
||||
class ShortCodeRelationFinder {
|
||||
class ShortCodeRelationFinder
|
||||
{
|
||||
|
||||
/**
|
||||
* @var String Regex matching a {@link DBField} class name which is shortcode capable.
|
||||
@ -24,13 +25,15 @@ class ShortCodeRelationFinder {
|
||||
* @param String Shortcode index number to find
|
||||
* @return array IDs
|
||||
*/
|
||||
function findPageIDs($number) {
|
||||
public function findPageIDs($number)
|
||||
{
|
||||
$list = $this->getList($number);
|
||||
$found = $list->column();
|
||||
return $found;
|
||||
}
|
||||
|
||||
function findPageCount($number) {
|
||||
public function findPageCount($number)
|
||||
{
|
||||
$list = $this->getList($number);
|
||||
return $list->count();
|
||||
}
|
||||
@ -38,13 +41,16 @@ class ShortCodeRelationFinder {
|
||||
/**
|
||||
* @return DataList
|
||||
*/
|
||||
function getList($number) {
|
||||
public function getList($number)
|
||||
{
|
||||
$list = DataList::create('SiteTree');
|
||||
$where = array();
|
||||
$fields = $this->getShortCodeFields('SiteTree');
|
||||
foreach($fields as $ancClass => $ancFields) {
|
||||
foreach($ancFields as $ancFieldName => $ancFieldSpec) {
|
||||
if ($ancClass != "SiteTree") $list = $list->leftJoin($ancClass,'"'.$ancClass.'"."ID" = "SiteTree"."ID"');
|
||||
foreach ($fields as $ancClass => $ancFields) {
|
||||
foreach ($ancFields as $ancFieldName => $ancFieldSpec) {
|
||||
if ($ancClass != "SiteTree") {
|
||||
$list = $list->leftJoin($ancClass, '"'.$ancClass.'"."ID" = "SiteTree"."ID"');
|
||||
}
|
||||
$where[] = "\"$ancClass\".\"$ancFieldName\" LIKE '%[dms_document_link,id=$number]%'"; //."%s" LIKE ""',
|
||||
}
|
||||
}
|
||||
@ -59,23 +65,29 @@ class ShortCodeRelationFinder {
|
||||
* @param String
|
||||
* @return Array Map of class names to an array of field names on these classes.
|
||||
*/
|
||||
function getShortcodeFields($class) {
|
||||
public function getShortcodeFields($class)
|
||||
{
|
||||
$fields = array();
|
||||
$ancestry = array_values(ClassInfo::dataClassesFor($class));
|
||||
|
||||
foreach($ancestry as $ancestor) {
|
||||
if(ClassInfo::classImplements($ancestor, 'TestOnly')) continue;
|
||||
foreach ($ancestry as $ancestor) {
|
||||
if (ClassInfo::classImplements($ancestor, 'TestOnly')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ancFields = DataObject::custom_database_fields($ancestor);
|
||||
if($ancFields) foreach($ancFields as $ancFieldName => $ancFieldSpec) {
|
||||
if(preg_match($this->fieldSpecRegex, $ancFieldSpec)) {
|
||||
if(!@$fields[$ancestor]) $fields[$ancestor] = array();
|
||||
if ($ancFields) {
|
||||
foreach ($ancFields as $ancFieldName => $ancFieldSpec) {
|
||||
if (preg_match($this->fieldSpecRegex, $ancFieldSpec)) {
|
||||
if (!@$fields[$ancestor]) {
|
||||
$fields[$ancestor] = array();
|
||||
}
|
||||
$fields[$ancestor][$ancFieldName] = $ancFieldSpec;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,32 +1,35 @@
|
||||
<?php
|
||||
class DMSDocumentTest extends SapphireTest {
|
||||
class DMSDocumentTest extends SapphireTest
|
||||
{
|
||||
|
||||
static $fixture_file = "dms/tests/dmstest.yml";
|
||||
public static $fixture_file = "dms/tests/dmstest.yml";
|
||||
|
||||
function tearDownOnce() {
|
||||
public function tearDownOnce()
|
||||
{
|
||||
self::$is_running_test = true;
|
||||
|
||||
$d = DataObject::get("DMSDocument");
|
||||
foreach($d as $d1) {
|
||||
foreach ($d as $d1) {
|
||||
$d1->delete();
|
||||
}
|
||||
$t = DataObject::get("DMSTag");
|
||||
foreach($t as $t1) {
|
||||
foreach ($t as $t1) {
|
||||
$t1->delete();
|
||||
}
|
||||
|
||||
self::$is_running_test = $this->originalIsRunningTest;
|
||||
}
|
||||
|
||||
function testPageRelations() {
|
||||
$s1 = $this->objFromFixture('SiteTree','s1');
|
||||
$s2 = $this->objFromFixture('SiteTree','s2');
|
||||
$s3 = $this->objFromFixture('SiteTree','s3');
|
||||
$s4 = $this->objFromFixture('SiteTree','s4');
|
||||
$s5 = $this->objFromFixture('SiteTree','s5');
|
||||
$s6 = $this->objFromFixture('SiteTree','s6');
|
||||
public function testPageRelations()
|
||||
{
|
||||
$s1 = $this->objFromFixture('SiteTree', 's1');
|
||||
$s2 = $this->objFromFixture('SiteTree', 's2');
|
||||
$s3 = $this->objFromFixture('SiteTree', 's3');
|
||||
$s4 = $this->objFromFixture('SiteTree', 's4');
|
||||
$s5 = $this->objFromFixture('SiteTree', 's5');
|
||||
$s6 = $this->objFromFixture('SiteTree', 's6');
|
||||
|
||||
$d1 = $this->objFromFixture('DMSDocument','d1');
|
||||
$d1 = $this->objFromFixture('DMSDocument', 'd1');
|
||||
|
||||
$pages = $d1->Pages();
|
||||
$pagesArray = $pages->toArray();
|
||||
@ -38,10 +41,11 @@ class DMSDocumentTest extends SapphireTest {
|
||||
$this->assertEquals($pagesArray[5]->ID, $s6->ID, "Page 6 associated correctly");
|
||||
}
|
||||
|
||||
function testAddPageRelation() {
|
||||
$s1 = $this->objFromFixture('SiteTree','s1');
|
||||
$s2 = $this->objFromFixture('SiteTree','s2');
|
||||
$s3 = $this->objFromFixture('SiteTree','s3');
|
||||
public function testAddPageRelation()
|
||||
{
|
||||
$s1 = $this->objFromFixture('SiteTree', 's1');
|
||||
$s2 = $this->objFromFixture('SiteTree', 's2');
|
||||
$s3 = $this->objFromFixture('SiteTree', 's3');
|
||||
|
||||
$doc = new DMSDocument();
|
||||
$doc->Filename = "test file";
|
||||
@ -77,9 +81,10 @@ class DMSDocumentTest extends SapphireTest {
|
||||
$this->assertNotContains($doc, $documentsArray, "Document no longer associated with page");
|
||||
}
|
||||
|
||||
function testDeletingPageWithAssociatedDocuments() {
|
||||
$s1 = $this->objFromFixture('SiteTree','s1');
|
||||
$s2 = $this->objFromFixture('SiteTree','s2');
|
||||
public function testDeletingPageWithAssociatedDocuments()
|
||||
{
|
||||
$s1 = $this->objFromFixture('SiteTree', 's1');
|
||||
$s2 = $this->objFromFixture('SiteTree', 's2');
|
||||
$s2->publish('Stage', 'Live');
|
||||
$s2ID = $s2->ID;
|
||||
|
||||
@ -93,7 +98,7 @@ class DMSDocumentTest extends SapphireTest {
|
||||
|
||||
$s1->delete();
|
||||
|
||||
$documents = DataObject::get("DMSDocument","\"Filename\" = 'delete test file'", false);
|
||||
$documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'", false);
|
||||
$this->assertEquals(
|
||||
$documents->Count(),
|
||||
'1',
|
||||
@ -101,7 +106,7 @@ class DMSDocumentTest extends SapphireTest {
|
||||
);
|
||||
|
||||
$s2->delete();
|
||||
$documents = DataObject::get("DMSDocument","\"Filename\" = 'delete test file'");
|
||||
$documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
|
||||
$this->assertEquals(
|
||||
$documents->Count(),
|
||||
'1',
|
||||
@ -111,7 +116,7 @@ class DMSDocumentTest extends SapphireTest {
|
||||
|
||||
$s2 = Versioned::get_one_by_stage('SiteTree', 'Live', sprintf('"SiteTree"."ID" = %d', $s2ID));
|
||||
$s2->doDeleteFromLive();
|
||||
$documents = DataObject::get("DMSDocument","\"Filename\" = 'delete test file'");
|
||||
$documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
|
||||
$this->assertEquals(
|
||||
$documents->Count(),
|
||||
'0',
|
||||
@ -120,8 +125,9 @@ class DMSDocumentTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
function testUnpublishPageWithAssociatedDocuments() {
|
||||
$s2 = $this->objFromFixture('SiteTree','s2');
|
||||
public function testUnpublishPageWithAssociatedDocuments()
|
||||
{
|
||||
$s2 = $this->objFromFixture('SiteTree', 's2');
|
||||
$s2->publish('Stage', 'Live');
|
||||
$s2ID = $s2->ID;
|
||||
|
||||
@ -133,7 +139,7 @@ class DMSDocumentTest extends SapphireTest {
|
||||
$doc->addPage($s2);
|
||||
|
||||
$s2->doDeleteFromLive();
|
||||
$documents = DataObject::get("DMSDocument","\"Filename\" = 'delete test file'");
|
||||
$documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
|
||||
$this->assertEquals(
|
||||
$documents->Count(),
|
||||
'1',
|
||||
@ -143,7 +149,7 @@ class DMSDocumentTest extends SapphireTest {
|
||||
|
||||
$s2 = Versioned::get_one_by_stage('SiteTree', 'Stage', sprintf('"SiteTree"."ID" = %d', $s2ID));
|
||||
$s2->delete();
|
||||
$documents = DataObject::get("DMSDocument","\"Filename\" = 'delete test file'");
|
||||
$documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
|
||||
$this->assertEquals(
|
||||
$documents->Count(),
|
||||
'0',
|
||||
@ -151,5 +157,4 @@ class DMSDocumentTest extends SapphireTest {
|
||||
."associated with causes that document to be deleted as well"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +1,34 @@
|
||||
<?php
|
||||
class DMSEmbargoTest extends SapphireTest {
|
||||
class DMSEmbargoTest extends SapphireTest
|
||||
{
|
||||
|
||||
static $fixture_file = "dms/tests/dmsembargotest.yml";
|
||||
public static $fixture_file = "dms/tests/dmsembargotest.yml";
|
||||
|
||||
function tearDownOnce() {
|
||||
public function tearDownOnce()
|
||||
{
|
||||
self::$is_running_test = true;
|
||||
|
||||
$d = DataObject::get("DMSDocument");
|
||||
foreach($d as $d1) {
|
||||
foreach ($d as $d1) {
|
||||
$d1->delete();
|
||||
}
|
||||
$t = DataObject::get("DMSTag");
|
||||
foreach($t as $t1) {
|
||||
foreach ($t as $t1) {
|
||||
$t1->delete();
|
||||
}
|
||||
|
||||
self::$is_running_test = $this->originalIsRunningTest;
|
||||
}
|
||||
|
||||
function createFakeHTTPRequest($id) {
|
||||
$r = new SS_HTTPRequest('GET','index/'.$id);
|
||||
public function createFakeHTTPRequest($id)
|
||||
{
|
||||
$r = new SS_HTTPRequest('GET', 'index/'.$id);
|
||||
$r->match('index/$ID');
|
||||
return $r;
|
||||
}
|
||||
|
||||
function testBasicEmbargo() {
|
||||
public function testBasicEmbargo()
|
||||
{
|
||||
$oldDMSFolder = DMS::$dmsFolder;
|
||||
DMS::$dmsFolder = DMS_DIR; //sneakily setting the DMS folder to the folder where the test file lives
|
||||
|
||||
@ -37,111 +41,114 @@ class DMSEmbargoTest extends SapphireTest {
|
||||
$controller = new DMSDocument_Controller();
|
||||
DMSDocument_Controller::$testMode = true;
|
||||
$result = $controller->index($this->createFakeHTTPRequest($docID));
|
||||
$this->assertEquals($doc->getFullPath(),$result,"Correct underlying file returned (in test mode)");
|
||||
$this->assertEquals($doc->getFullPath(), $result, "Correct underlying file returned (in test mode)");
|
||||
|
||||
$doc->embargoIndefinitely();
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$result = $controller->index($this->createFakeHTTPRequest($docID));
|
||||
$this->assertEquals($doc->getFullPath(),$result,"Admins can still download embargoed files");
|
||||
$this->assertEquals($doc->getFullPath(), $result, "Admins can still download embargoed files");
|
||||
|
||||
$this->logInWithPermission('random-user-group');
|
||||
$result = $controller->index($this->createFakeHTTPRequest($docID));
|
||||
$this->assertNotEquals($doc->getFullPath(),$result,"File no longer returned (in test mode) when switching to other user group");
|
||||
$this->assertNotEquals($doc->getFullPath(), $result, "File no longer returned (in test mode) when switching to other user group");
|
||||
|
||||
DMS::$dmsFolder = $oldDMSFolder;
|
||||
}
|
||||
|
||||
function testEmbargoIndefinitely() {
|
||||
public function testEmbargoIndefinitely()
|
||||
{
|
||||
$doc = new DMSDocument();
|
||||
$doc->Filename = "DMS-test-lorum-file.pdf";
|
||||
$doc->Folder = "tests";
|
||||
$doc->write();
|
||||
|
||||
$doc->embargoIndefinitely();
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(),"Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$doc->clearEmbargo();
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
}
|
||||
|
||||
function testExpireAtDate() {
|
||||
public function testExpireAtDate()
|
||||
{
|
||||
$doc = new DMSDocument();
|
||||
$doc->Filename = "DMS-test-lorum-file.pdf";
|
||||
$doc->Folder = "tests";
|
||||
$doc->write();
|
||||
|
||||
$doc->expireAtDate(strtotime('-1 second'));
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertTrue($doc->isExpired(),"Document is expired");
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertTrue($doc->isExpired(), "Document is expired");
|
||||
|
||||
$expireTime = "2019-04-05 11:43:13";
|
||||
$doc->expireAtDate($expireTime);
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
SS_Datetime::set_mock_now($expireTime);
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertTrue($doc->isExpired(),"Document is expired");
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertTrue($doc->isExpired(), "Document is expired");
|
||||
SS_Datetime::clear_mock_now();
|
||||
|
||||
$doc->expireAtDate(strtotime('-1 second'));
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertTrue($doc->isExpired(),"Document is expired");
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertTrue($doc->isExpired(), "Document is expired");
|
||||
|
||||
$doc->clearExpiry();
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
}
|
||||
|
||||
function testEmbargoUntilDate() {
|
||||
public function testEmbargoUntilDate()
|
||||
{
|
||||
$doc = new DMSDocument();
|
||||
$doc->Filename = "DMS-test-lorum-file.pdf";
|
||||
$doc->Folder = "tests";
|
||||
$doc->write();
|
||||
|
||||
$doc->embargoUntilDate(strtotime('+1 minute'));
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(),"Document is embargoed");
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
||||
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$doc->embargoUntilDate(strtotime('-1 second'));
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$embargoTime = "2019-04-05 11:43:13";
|
||||
$doc->embargoUntilDate($embargoTime);
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(),"Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
SS_Datetime::set_mock_now($embargoTime);
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
SS_Datetime::clear_mock_now();
|
||||
|
||||
$doc->clearEmbargo();
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
}
|
||||
|
||||
function testEmbargoUntilPublished() {
|
||||
$s1 = $this->objFromFixture('SiteTree','s1');
|
||||
public function testEmbargoUntilPublished()
|
||||
{
|
||||
$s1 = $this->objFromFixture('SiteTree', 's1');
|
||||
|
||||
$doc = new DMSDocument();
|
||||
$doc->Filename = "test file";
|
||||
@ -150,47 +157,47 @@ class DMSEmbargoTest extends SapphireTest {
|
||||
|
||||
$doc->addPage($s1);
|
||||
|
||||
$s1->publish('Stage','Live');
|
||||
$s1->publish('Stage', 'Live');
|
||||
$s1->doPublish();
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$doc->embargoUntilPublished();
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(),"Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$s1->publish('Stage','Live');
|
||||
$s1->publish('Stage', 'Live');
|
||||
$s1->doPublish();
|
||||
$doc = DataObject::get_by_id("DMSDocument",$dID);
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$doc->embargoUntilPublished();
|
||||
$doc = DataObject::get_by_id("DMSDocument",$dID);
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(),"Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$doc->embargoIndefinitely();
|
||||
$doc = DataObject::get_by_id("DMSDocument",$dID);
|
||||
$this->assertTrue($doc->isHidden(),"Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(),"Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
||||
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
||||
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$s1->publish('Stage','Live');
|
||||
$s1->publish('Stage', 'Live');
|
||||
$s1->doPublish();
|
||||
$doc = DataObject::get_by_id("DMSDocument",$dID);
|
||||
$this->assertTrue($doc->isHidden(),"Document is still hidden because although the untilPublish flag is cleared, the indefinitely flag is still there");
|
||||
$this->assertTrue($doc->isEmbargoed(),"Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
||||
$this->assertTrue($doc->isHidden(), "Document is still hidden because although the untilPublish flag is cleared, the indefinitely flag is still there");
|
||||
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
|
||||
$doc->clearEmbargo();
|
||||
$doc = DataObject::get_by_id("DMSDocument",$dID);
|
||||
$this->assertFalse($doc->isHidden(),"Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(),"Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(),"Document is not expired");
|
||||
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
||||
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
||||
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
||||
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
||||
}
|
||||
}
|
@ -5,9 +5,11 @@
|
||||
* @package dms
|
||||
* @subpackage tests
|
||||
*/
|
||||
class DMSShortcodeTest extends SapphireTest {
|
||||
class DMSShortcodeTest extends SapphireTest
|
||||
{
|
||||
|
||||
public function testShortcodeOperation() {
|
||||
public function testShortcodeOperation()
|
||||
{
|
||||
$file = 'dms/tests/DMS-test-lorum-file.pdf';
|
||||
$document = DMS::inst()->storeDocument($file);
|
||||
|
||||
@ -22,5 +24,4 @@ class DMSShortcodeTest extends SapphireTest {
|
||||
$this->assertEquals($document->getExtension(), $link->getAttribute('data-ext'));
|
||||
$this->assertEquals($document->getFileSizeFormatted(), $link->getAttribute('data-size'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,118 +1,121 @@
|
||||
<?php
|
||||
class DMSTagTest extends SapphireTest {
|
||||
class DMSTagTest extends SapphireTest
|
||||
{
|
||||
|
||||
function tearDownOnce() {
|
||||
public function tearDownOnce()
|
||||
{
|
||||
self::$is_running_test = true;
|
||||
|
||||
$d = DataObject::get("DMSDocument");
|
||||
foreach($d as $d1) {
|
||||
foreach ($d as $d1) {
|
||||
$d1->delete();
|
||||
}
|
||||
$t = DataObject::get("DMSTag");
|
||||
foreach($t as $t1) {
|
||||
foreach ($t as $t1) {
|
||||
$t1->delete();
|
||||
}
|
||||
|
||||
self::$is_running_test = $this->originalIsRunningTest;
|
||||
}
|
||||
|
||||
function testAddingTags() {
|
||||
public function testAddingTags()
|
||||
{
|
||||
$doc = new DMSDocument();
|
||||
$doc->Filename = "test file";
|
||||
$doc->Folder = "0";
|
||||
$doc->write();
|
||||
|
||||
$doc->addTag("fruit","banana");
|
||||
$doc->addTag("fruit","orange");
|
||||
$doc->addTag("fruit","apple");
|
||||
$doc->addTag("company","apple");
|
||||
$doc->addTag("company","SilverStripe");
|
||||
$doc->addTag("fruit", "banana");
|
||||
$doc->addTag("fruit", "orange");
|
||||
$doc->addTag("fruit", "apple");
|
||||
$doc->addTag("company", "apple");
|
||||
$doc->addTag("company", "SilverStripe");
|
||||
|
||||
$fruits = $doc->getTagsList("fruit");
|
||||
$this->assertNotNull($fruits,"Something returned for fruit tags");
|
||||
$this->assertEquals(count($fruits),3,"3 fruit tags returned");
|
||||
$this->assertTrue(in_array("banana",$fruits),"correct fruit tags returned");
|
||||
$this->assertNotNull($fruits, "Something returned for fruit tags");
|
||||
$this->assertEquals(count($fruits), 3, "3 fruit tags returned");
|
||||
$this->assertTrue(in_array("banana", $fruits), "correct fruit tags returned");
|
||||
|
||||
//sneakily create another document and link one of the tags to that, too
|
||||
$doc2 = new DMSDocument();
|
||||
$doc2->Filename = "sneaky file";
|
||||
$doc2->Folder = "0";
|
||||
$doc2->write();
|
||||
$doc2->addTag("fruit","banana");
|
||||
$doc2->addTag("fruit", "banana");
|
||||
|
||||
$fruits = $doc2->getTagsList("fruit");
|
||||
$this->assertNotNull($fruits,"Something returned for fruit tags");
|
||||
$this->assertEquals(count($fruits),1,"Only 1 fruit tags returned");
|
||||
$this->assertNotNull($fruits, "Something returned for fruit tags");
|
||||
$this->assertEquals(count($fruits), 1, "Only 1 fruit tags returned");
|
||||
|
||||
//tidy up by deleting all tags from doc 1 (But the banana fruit tag should remain)
|
||||
$doc->removeAllTags();
|
||||
|
||||
//banana fruit remains
|
||||
$fruits = $doc2->getTagsList("fruit");
|
||||
$this->assertNotNull($fruits,"Something returned for fruit tags");
|
||||
$this->assertEquals(count($fruits),1,"Only 1 fruit tags returned");
|
||||
$this->assertNotNull($fruits, "Something returned for fruit tags");
|
||||
$this->assertEquals(count($fruits), 1, "Only 1 fruit tags returned");
|
||||
|
||||
$tags = DataObject::get("DMSTag");
|
||||
$this->assertEquals($tags->Count(),1,"A single DMS tag objects remain after deletion of all tags on doc1");
|
||||
$this->assertEquals($tags->Count(), 1, "A single DMS tag objects remain after deletion of all tags on doc1");
|
||||
|
||||
//delete all tags off doc2 to complete the tidy up
|
||||
$doc2->removeAllTags();
|
||||
|
||||
$tags = DataObject::get("DMSTag");
|
||||
$this->assertEquals($tags->Count(),0,"No DMS tag objects remain after deletion");
|
||||
$this->assertEquals($tags->Count(), 0, "No DMS tag objects remain after deletion");
|
||||
}
|
||||
|
||||
function testRemovingTags() {
|
||||
public function testRemovingTags()
|
||||
{
|
||||
$doc = new DMSDocument();
|
||||
$doc->Filename = "test file";
|
||||
$doc->Folder = "0";
|
||||
$doc->write();
|
||||
|
||||
$doc->addTag("fruit","banana");
|
||||
$doc->addTag("fruit","orange");
|
||||
$doc->addTag("fruit","apple");
|
||||
$doc->addTag("company","apple");
|
||||
$doc->addTag("company","SilverStripe");
|
||||
$doc->addTag("fruit", "banana");
|
||||
$doc->addTag("fruit", "orange");
|
||||
$doc->addTag("fruit", "apple");
|
||||
$doc->addTag("company", "apple");
|
||||
$doc->addTag("company", "SilverStripe");
|
||||
|
||||
$companies = $doc->getTagsList("company");
|
||||
$this->assertNotNull($companies,"Companies returned before deletion");
|
||||
$this->assertEquals(count($companies),2,"Two companies returned before deletion");
|
||||
$this->assertNotNull($companies, "Companies returned before deletion");
|
||||
$this->assertEquals(count($companies), 2, "Two companies returned before deletion");
|
||||
|
||||
//delete an entire category
|
||||
$doc->removeTag("company");
|
||||
|
||||
$companies = $doc->getTagsList("company");
|
||||
$this->assertNull($companies,"All companies deleted");
|
||||
$this->assertNull($companies, "All companies deleted");
|
||||
|
||||
$fruit = $doc->getTagsList("fruit");
|
||||
$this->assertEquals(count($fruit),3,"Three fruits returned before deletion");
|
||||
$this->assertEquals(count($fruit), 3, "Three fruits returned before deletion");
|
||||
|
||||
//delete a single tag
|
||||
$doc->removeTag("fruit","apple");
|
||||
$doc->removeTag("fruit", "apple");
|
||||
|
||||
$fruit = $doc->getTagsList("fruit");
|
||||
$this->assertEquals(count($fruit),2,"Two fruits returned after deleting one");
|
||||
$this->assertEquals(count($fruit), 2, "Two fruits returned after deleting one");
|
||||
|
||||
//delete a single tag
|
||||
$doc->removeTag("fruit","orange");
|
||||
$doc->removeTag("fruit", "orange");
|
||||
|
||||
$fruit = $doc->getTagsList("fruit");
|
||||
$this->assertEquals(count($fruit),1,"One fruits returned after deleting two");
|
||||
$this->assertEquals(count($fruit), 1, "One fruits returned after deleting two");
|
||||
|
||||
//nothing happens when deleting tag that doesn't exist
|
||||
$doc->removeTag("fruit","jellybean");
|
||||
$doc->removeTag("fruit", "jellybean");
|
||||
|
||||
$fruit = $doc->getTagsList("fruit");
|
||||
$this->assertEquals(count($fruit),1,"One fruits returned after attempting to delete non-existent fruit");
|
||||
$this->assertEquals(count($fruit), 1, "One fruits returned after attempting to delete non-existent fruit");
|
||||
|
||||
//delete the last fruit
|
||||
$doc->removeTag("fruit","banana");
|
||||
$doc->removeTag("fruit", "banana");
|
||||
|
||||
$fruit = $doc->getTagsList("fruit");
|
||||
$this->assertNull($fruit,"All fruits deleted");
|
||||
$this->assertNull($fruit, "All fruits deleted");
|
||||
|
||||
$tags = DataObject::get("DMSTag");
|
||||
$this->assertEquals($tags->Count(),0,"No DMS tag objects remain after deletion");
|
||||
$this->assertEquals($tags->Count(), 0, "No DMS tag objects remain after deletion");
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
<?php
|
||||
class DMSTest extends FunctionalTest {
|
||||
class DMSTest extends FunctionalTest
|
||||
{
|
||||
|
||||
static $testFile = 'dms/tests/DMS-test-lorum-file.pdf';
|
||||
static $testFile2 = 'dms/tests/DMS-test-document-2.pdf';
|
||||
public static $testFile = 'dms/tests/DMS-test-lorum-file.pdf';
|
||||
public static $testFile2 = 'dms/tests/DMS-test-document-2.pdf';
|
||||
|
||||
//store values to reset back to after this test runs
|
||||
static $dmsFolderOld;
|
||||
static $dmsFolderSizeOld;
|
||||
public static $dmsFolderOld;
|
||||
public static $dmsFolderSizeOld;
|
||||
|
||||
function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
self::$dmsFolderOld = DMS::$dmsFolder;
|
||||
@ -21,17 +23,18 @@ class DMSTest extends FunctionalTest {
|
||||
$this->delete(BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-1234');
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
self::$is_running_test = true;
|
||||
|
||||
$d = DataObject::get("DMSDocument");
|
||||
foreach($d as $d1) {
|
||||
foreach ($d as $d1) {
|
||||
$d1->delete();
|
||||
}
|
||||
$t = DataObject::get("DMSTag");
|
||||
foreach($t as $t1) {
|
||||
foreach ($t as $t1) {
|
||||
$t1->delete();
|
||||
}
|
||||
|
||||
@ -45,7 +48,8 @@ class DMSTest extends FunctionalTest {
|
||||
self::$is_running_test = $this->originalIsRunningTest;
|
||||
}
|
||||
|
||||
public function delete($path) {
|
||||
public function delete($path)
|
||||
{
|
||||
if (file_exists($path) || is_dir($path)) {
|
||||
$it = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($path),
|
||||
@ -65,26 +69,28 @@ class DMSTest extends FunctionalTest {
|
||||
}
|
||||
|
||||
|
||||
function testDMSStorage() {
|
||||
public function testDMSStorage()
|
||||
{
|
||||
$dms = DMS::inst();
|
||||
|
||||
$file = self::$testFile;
|
||||
$document = $dms->storeDocument($file);
|
||||
|
||||
$this->assertNotNull($document, "Document object created");
|
||||
$this->assertTrue(file_exists(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename),"Document file copied into DMS folder");
|
||||
$this->assertTrue(file_exists(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename), "Document file copied into DMS folder");
|
||||
|
||||
//$title = $document->getTag('title');
|
||||
}
|
||||
|
||||
function testDMSFolderSpanning() {
|
||||
public function testDMSFolderSpanning()
|
||||
{
|
||||
DMS::$dmsFolderSize = 5;
|
||||
$dms = DMS::inst();
|
||||
|
||||
$file = self::$testFile;
|
||||
|
||||
$documents = array();
|
||||
for($i = 0; $i <= 16; $i++) {
|
||||
for ($i = 0; $i <= 16; $i++) {
|
||||
$document = $dms->storeDocument($file);
|
||||
$this->assertNotNull($document, "Document object created on run number: $i");
|
||||
$this->assertTrue(file_exists($document->getFullPath()));
|
||||
@ -93,19 +99,20 @@ class DMSTest extends FunctionalTest {
|
||||
|
||||
//test document objects have their folders set
|
||||
$folders = array();
|
||||
for($i = 0; $i <= 16; $i++) {
|
||||
for ($i = 0; $i <= 16; $i++) {
|
||||
$folderName = $documents[$i]->Folder;
|
||||
$this->assertTrue(strpos($documents[$i]->getFullPath(), DIRECTORY_SEPARATOR . $folderName . DIRECTORY_SEPARATOR) !== false, "Correct folder name for the documents. Document path contains reference to folder name '$folderName'");
|
||||
$folders[] = $folderName;
|
||||
}
|
||||
|
||||
//test we created 4 folder to contain the 17 files
|
||||
foreach($folders as $f) {
|
||||
$this->assertTrue(is_dir(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $f),"Document folder '$f' exists");
|
||||
foreach ($folders as $f) {
|
||||
$this->assertTrue(is_dir(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $f), "Document folder '$f' exists");
|
||||
}
|
||||
}
|
||||
|
||||
function testReplaceDocument() {
|
||||
public function testReplaceDocument()
|
||||
{
|
||||
$dms = DMS::inst();
|
||||
|
||||
//store the first document
|
||||
@ -118,14 +125,15 @@ class DMSTest extends FunctionalTest {
|
||||
$document = $document->replaceDocument(self::$testFile2);
|
||||
|
||||
$this->assertNotNull($document, "Document object created");
|
||||
$this->assertTrue(file_exists(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename),"Document file copied into DMS folder");
|
||||
$this->assertContains("DMS-test-document-2",$document->Filename, "Original document filename is contain in the new filename");
|
||||
$this->assertEquals("My custom title", $document->Title , "Custom title not modified");
|
||||
$this->assertTrue(file_exists(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename), "Document file copied into DMS folder");
|
||||
$this->assertContains("DMS-test-document-2", $document->Filename, "Original document filename is contain in the new filename");
|
||||
$this->assertEquals("My custom title", $document->Title, "Custom title not modified");
|
||||
$this->assertEquals("My custom description", $document->Description, "Custom description not modified");
|
||||
}
|
||||
|
||||
function testDownloadDocument() {
|
||||
// $dms = DMS::inst();
|
||||
public function testDownloadDocument()
|
||||
{
|
||||
// $dms = DMS::inst();
|
||||
//
|
||||
// //store the first document
|
||||
// $document = $dms->storeDocument(self::$testFile);
|
||||
@ -137,6 +145,4 @@ class DMSTest extends FunctionalTest {
|
||||
// //$response = $this->get($link);
|
||||
// Debug::show($response);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
<?php
|
||||
class DMSVersioningTest extends SapphireTest {
|
||||
class DMSVersioningTest extends SapphireTest
|
||||
{
|
||||
|
||||
static $testFile = 'dms/tests/DMS-test-lorum-file.pdf';
|
||||
static $testFile2 = 'dms/tests/DMS-test-document-2.pdf';
|
||||
public static $testFile = 'dms/tests/DMS-test-lorum-file.pdf';
|
||||
public static $testFile2 = 'dms/tests/DMS-test-document-2.pdf';
|
||||
|
||||
//store values to reset back to after this test runs
|
||||
static $dmsFolderOld;
|
||||
static $dmsFolderSizeOld;
|
||||
static $dmsEnableVersionsOld;
|
||||
public static $dmsFolderOld;
|
||||
public static $dmsFolderSizeOld;
|
||||
public static $dmsEnableVersionsOld;
|
||||
|
||||
function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
self::$dmsFolderOld = DMS::$dmsFolder;
|
||||
@ -24,13 +26,14 @@ class DMSVersioningTest extends SapphireTest {
|
||||
$this->delete(BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-versions');
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
$d = DataObject::get("DMSDocument");
|
||||
foreach($d as $d1) {
|
||||
foreach ($d as $d1) {
|
||||
$d1->delete();
|
||||
}
|
||||
$t = DataObject::get("DMSTag");
|
||||
foreach($t as $t1) {
|
||||
foreach ($t as $t1) {
|
||||
$t1->delete();
|
||||
}
|
||||
|
||||
@ -45,7 +48,8 @@ class DMSVersioningTest extends SapphireTest {
|
||||
DMSDocument_versions::$enable_versions = self::$dmsEnableVersionsOld;
|
||||
}
|
||||
|
||||
public function delete($path) {
|
||||
public function delete($path)
|
||||
{
|
||||
if (file_exists($path) || is_dir($path)) {
|
||||
$it = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($path),
|
||||
@ -65,13 +69,14 @@ class DMSVersioningTest extends SapphireTest {
|
||||
}
|
||||
|
||||
|
||||
function testDMSVersionStorage() {
|
||||
public function testDMSVersionStorage()
|
||||
{
|
||||
$dms = DMS::inst();
|
||||
|
||||
$document = $dms->storeDocument(self::$testFile);
|
||||
|
||||
$this->assertNotNull($document, "Document object created");
|
||||
$this->assertTrue(file_exists(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename),"Document file copied into DMS folder");
|
||||
$this->assertTrue(file_exists(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename), "Document file copied into DMS folder");
|
||||
|
||||
$document->replaceDocument(self::$testFile2);
|
||||
$document->replaceDocument(self::$testFile);
|
||||
@ -80,16 +85,12 @@ class DMSVersioningTest extends SapphireTest {
|
||||
|
||||
$versionsList = $document->getVersions();
|
||||
|
||||
$this->assertEquals(4, $versionsList->Count(),"4 Versions created");
|
||||
$this->assertEquals(4, $versionsList->Count(), "4 Versions created");
|
||||
$versionsArray = $versionsList->toArray();
|
||||
|
||||
$this->assertEquals($versionsArray[0]->VersionCounter, 1,"Correct version count");
|
||||
$this->assertEquals($versionsArray[1]->VersionCounter, 2,"Correct version count");
|
||||
$this->assertEquals($versionsArray[2]->VersionCounter, 3,"Correct version count");
|
||||
$this->assertEquals($versionsArray[3]->VersionCounter, 4,"Correct version count");
|
||||
|
||||
$this->assertEquals($versionsArray[0]->VersionCounter, 1, "Correct version count");
|
||||
$this->assertEquals($versionsArray[1]->VersionCounter, 2, "Correct version count");
|
||||
$this->assertEquals($versionsArray[2]->VersionCounter, 3, "Correct version count");
|
||||
$this->assertEquals($versionsArray[3]->VersionCounter, 4, "Correct version count");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
<?php
|
||||
class ShortCodeRelationFinderTest extends SapphireTest {
|
||||
class ShortCodeRelationFinderTest extends SapphireTest
|
||||
{
|
||||
|
||||
static $fixture_file = array(
|
||||
public static $fixture_file = array(
|
||||
'dms/tests/dmstest.yml'
|
||||
);
|
||||
|
||||
function testFindInRate() {
|
||||
public function testFindInRate()
|
||||
{
|
||||
$d1 = $this->objFromFixture('DMSDocument', 'd1');
|
||||
$d2 = $this->objFromFixture('DMSDocument', 'd2');
|
||||
|
||||
@ -31,5 +33,4 @@ class ShortCodeRelationFinderTest extends SapphireTest {
|
||||
$this->assertContains($page1ID, $ids);
|
||||
$this->assertContains($page3ID, $ids);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user