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