1<?php 2 3namespace dokuwiki\plugin\extension; 4 5/** 6 * Manages info about installation/deinstallation of extensions 7 */ 8class Manager 9{ 10 /** @var Extension The managed extension */ 11 protected Extension $extension; 12 13 /** @var string path to the manager.dat */ 14 protected string $path; 15 16 /** @var array the data from the manager.dat */ 17 protected array $data = []; 18 19 /** 20 * Initialize the Manager 21 * 22 * @param Extension $extension 23 */ 24 public function __construct(Extension $extension) 25 { 26 $this->extension = $extension; 27 $this->path = $this->extension->getInstallDir() . '/manager.dat'; 28 $this->data = $this->readFile(); 29 } 30 31 /** 32 * This updates the timestamp and URL in the manager.dat file 33 * 34 * It is called by Installer when installing or updating an extension 35 * 36 * @param $url 37 */ 38 public function storeUpdate($url) 39 { 40 $this->data['downloadurl'] = $url; 41 if (isset($this->data['installed'])) { 42 // it's an update 43 $this->data['updated'] = date('r'); 44 } else { 45 // it's a new install 46 $this->data['installed'] = date('r'); 47 } 48 49 $data = ''; 50 foreach ($this->data as $k => $v) { 51 $data .= $k . '=' . $v . DOKU_LF; 52 } 53 io_saveFile($this->path, $data); 54 } 55 56 57 58 /** 59 * Reads the manager.dat file and fills the managerInfo array 60 */ 61 protected function readFile() 62 { 63 $data = []; 64 if (!is_readable($this->path)) return $data; 65 66 $file = (array)@file($this->path); 67 foreach ($file as $line) { 68 [$key, $value] = sexplode('=', $line, 2, ''); 69 $key = trim($key); 70 $value = trim($value); 71 // backwards compatible with old plugin manager 72 if ($key == 'url') $key = 'downloadurl'; 73 $data[$key] = $value; 74 } 75 76 return $data; 77 } 78} 79