1<?php 2 3namespace dokuwiki\plugin\structpublish\meta; 4 5use dokuwiki\plugin\struct\meta\AccessTableSerial; 6 7/** 8 * Class AccessTableStructpublish 9 * 10 * Load and save serial data 11 * 12 * @package dokuwiki\plugin\struct\meta 13 */ 14class AccessTableStructpublish extends AccessTableSerial 15{ 16 public function __construct($table, $pid, $ts = 0, $rid = 0) 17 { 18 parent::__construct($table, $pid, $ts, $rid); 19 } 20 21 /** 22 * @inheritDoc 23 */ 24 protected function getSingleSql() 25 { 26 $cols = array_merge($this->getSingleNoninputCols(), $this->singleCols); 27 $cols = join(',', $cols); 28 $vals = array_merge($this->getSingleNoninputValues(), $this->singleValues); 29 $rid = $this->getRid() ?: "(SELECT (COALESCE(MAX(rid), 0 ) + 1) FROM $this->stable)"; 30 31 return "REPLACE INTO $this->stable (rid, $cols) 32 VALUES ($rid," . trim(str_repeat('?,', count($vals)), ',') . ');'; 33 } 34 35 /** 36 * @inheritDoc 37 */ 38 protected function getMultiSql() 39 { 40 return ''; 41 } 42 43 /** 44 * @return int|bool 45 */ 46 protected function getLastRevisionTimestamp() 47 { 48 $table = 'data_structpublish'; 49 $where = "WHERE pid = ?"; 50 $opts = [$this->pid]; 51 if ($this->ts) { 52 $where .= " AND REV > 0 AND rev <= ?"; 53 $opts[] = $this->ts; 54 } 55 56 /** @noinspection SqlResolve */ 57 $sql = "SELECT rev FROM $table $where ORDER BY rev DESC LIMIT 1"; 58 $res = $this->sqlite->query($sql, $opts); 59 $ret = $this->sqlite->res2single($res); 60 $this->sqlite->res_close($res); 61 // make sure we don't cast empty result to 0 (serial data has rev = 0) 62 if ($ret !== false) $ret = (int)$ret; 63 return $ret; 64 } 65} 66