1<?php 2 3 4use ComboStrap\ExceptionCombo; 5use ComboStrap\FileSystems; 6use ComboStrap\MetaManagerForm; 7use ComboStrap\LogUtility; 8use ComboStrap\Metadata; 9use ComboStrap\MetadataDateTime; 10use ComboStrap\MetadataDokuWikiStore; 11use ComboStrap\Page; 12use ComboStrap\PageCreationDate; 13 14class ModificationDate extends MetadataDateTime 15{ 16 17 public const PROPERTY_NAME = 'date_modified'; 18 19 public static function createForPage(Page $page) 20 { 21 return (new ModificationDate()) 22 ->setResource($page); 23 } 24 25 public function getTab(): string 26 { 27 return MetaManagerForm::TAB_PAGE_VALUE; 28 } 29 30 public function buildFromReadStore(): MetadataDateTime 31 { 32 $store = $this->getReadStore(); 33 if (!($store instanceof MetadataDokuWikiStore)) { 34 return parent::buildFromReadStore(); 35 } 36 37 $modificationTime = FileSystems::getModifiedTime($this->getResource()->getPath()); 38 if ($modificationTime !== null) { 39 $this->setValue($modificationTime); 40 return $this; 41 } 42 43 /** 44 * Dokuwiki 45 * Why do they store the date of the file while it's in the file system ? 46 */ 47 $createdMeta = $store->getCurrentFromName('date')['modified']; 48 if (empty($createdMeta)) { 49 $createdMeta = $store->getFromPersistentName('date')['modified']; 50 if (empty($createdMeta)) { 51 return $this; 52 } 53 } 54 // the data in dokuwiki is saved as timestamp 55 $datetime = new DateTime(); 56 if(!is_int($createdMeta)){ 57 LogUtility::msg("The modification time in the dokuwiki meta is not an integer"); 58 return $this; 59 } 60 $datetime->setTimestamp($createdMeta); 61 $this->setValue($datetime); 62 return $this; 63 } 64 65 66 public function getDescription(): string 67 { 68 return "The last modification date of the page"; // resource 69 } 70 71 public function getLabel(): string 72 { 73 return "Modification Date"; 74 } 75 76 static public function getName(): string 77 { 78 return self::PROPERTY_NAME; 79 } 80 81 public function getPersistenceType(): string 82 { 83 return Metadata::DERIVED_METADATA; 84 } 85 86 public function getMutable(): bool 87 { 88 return false; 89 } 90 91 public function getDefaultValue(): ?DateTime 92 { 93 94 $modificationTime = FileSystems::getModifiedTime($this->getResource()->getPath()); 95 if ($modificationTime !== null) { 96 return $modificationTime; 97 } 98 return PageCreationDate::createForPage($this->getResource())->getValue(); 99 100 } 101 102 public function getCanonical(): string 103 { 104 return Metadata::CANONICAL; 105 } 106 107 108} 109