Database.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. <?php
  2. /**
  3. * PrivateBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link https://github.com/PrivateBin/PrivateBin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. * @version 1.2.1
  11. */
  12. namespace PrivateBin\Data;
  13. use Exception;
  14. use PDO;
  15. use PDOException;
  16. use PrivateBin\Controller;
  17. use stdClass;
  18. /**
  19. * Database
  20. *
  21. * Model for database access, implemented as a singleton.
  22. */
  23. class Database extends AbstractData
  24. {
  25. /**
  26. * cache for select queries
  27. *
  28. * @var array
  29. */
  30. private static $_cache = array();
  31. /**
  32. * instance of database connection
  33. *
  34. * @access private
  35. * @static
  36. * @var PDO
  37. */
  38. private static $_db;
  39. /**
  40. * table prefix
  41. *
  42. * @access private
  43. * @static
  44. * @var string
  45. */
  46. private static $_prefix = '';
  47. /**
  48. * database type
  49. *
  50. * @access private
  51. * @static
  52. * @var string
  53. */
  54. private static $_type = '';
  55. /**
  56. * get instance of singleton
  57. *
  58. * @access public
  59. * @static
  60. * @param array $options
  61. * @throws Exception
  62. * @return Database
  63. */
  64. public static function getInstance($options = null)
  65. {
  66. // if needed initialize the singleton
  67. if (!(self::$_instance instanceof self)) {
  68. self::$_instance = new self;
  69. }
  70. if (is_array($options)) {
  71. // set table prefix if given
  72. if (array_key_exists('tbl', $options)) {
  73. self::$_prefix = $options['tbl'];
  74. }
  75. // initialize the db connection with new options
  76. if (
  77. array_key_exists('dsn', $options) &&
  78. array_key_exists('usr', $options) &&
  79. array_key_exists('pwd', $options) &&
  80. array_key_exists('opt', $options)
  81. ) {
  82. // set default options
  83. $options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
  84. $options['opt'][PDO::ATTR_EMULATE_PREPARES] = false;
  85. $options['opt'][PDO::ATTR_PERSISTENT] = true;
  86. $db_tables_exist = true;
  87. // setup type and dabase connection
  88. self::$_type = strtolower(
  89. substr($options['dsn'], 0, strpos($options['dsn'], ':'))
  90. );
  91. $tableQuery = self::_getTableQuery(self::$_type);
  92. self::$_db = new PDO(
  93. $options['dsn'],
  94. $options['usr'],
  95. $options['pwd'],
  96. $options['opt']
  97. );
  98. // check if the database contains the required tables
  99. $tables = self::$_db->query($tableQuery)->fetchAll(PDO::FETCH_COLUMN, 0);
  100. // create paste table if necessary
  101. if (!in_array(self::_sanitizeIdentifier('paste'), $tables)) {
  102. self::_createPasteTable();
  103. $db_tables_exist = false;
  104. }
  105. // create comment table if necessary
  106. if (!in_array(self::_sanitizeIdentifier('comment'), $tables)) {
  107. self::_createCommentTable();
  108. $db_tables_exist = false;
  109. }
  110. // create config table if necessary
  111. $db_version = Controller::VERSION;
  112. if (!in_array(self::_sanitizeIdentifier('config'), $tables)) {
  113. self::_createConfigTable();
  114. // if we only needed to create the config table, the DB is older then 0.22
  115. if ($db_tables_exist) {
  116. $db_version = '0.21';
  117. }
  118. } else {
  119. $db_version = self::_getConfig('VERSION');
  120. }
  121. // update database structure if necessary
  122. if (version_compare($db_version, Controller::VERSION, '<')) {
  123. self::_upgradeDatabase($db_version);
  124. }
  125. } else {
  126. throw new Exception(
  127. 'Missing configuration for key dsn, usr, pwd or opt in the section model_options, please check your configuration file', 6
  128. );
  129. }
  130. }
  131. return self::$_instance;
  132. }
  133. /**
  134. * Create a paste.
  135. *
  136. * @access public
  137. * @param string $pasteid
  138. * @param array $paste
  139. * @return bool
  140. */
  141. public function create($pasteid, $paste)
  142. {
  143. if (
  144. array_key_exists($pasteid, self::$_cache)
  145. ) {
  146. if (false !== self::$_cache[$pasteid]) {
  147. return false;
  148. } else {
  149. unset(self::$_cache[$pasteid]);
  150. }
  151. }
  152. $opendiscussion = $burnafterreading = false;
  153. $attachment = $attachmentname = '';
  154. $meta = $paste['meta'];
  155. unset($meta['postdate']);
  156. $expire_date = 0;
  157. if (array_key_exists('expire_date', $paste['meta'])) {
  158. $expire_date = (int) $paste['meta']['expire_date'];
  159. unset($meta['expire_date']);
  160. }
  161. if (array_key_exists('opendiscussion', $paste['meta'])) {
  162. $opendiscussion = (bool) $paste['meta']['opendiscussion'];
  163. unset($meta['opendiscussion']);
  164. }
  165. if (array_key_exists('burnafterreading', $paste['meta'])) {
  166. $burnafterreading = (bool) $paste['meta']['burnafterreading'];
  167. unset($meta['burnafterreading']);
  168. }
  169. if (array_key_exists('attachment', $paste['meta'])) {
  170. $attachment = $paste['meta']['attachment'];
  171. unset($meta['attachment']);
  172. }
  173. if (array_key_exists('attachmentname', $paste['meta'])) {
  174. $attachmentname = $paste['meta']['attachmentname'];
  175. unset($meta['attachmentname']);
  176. }
  177. return self::_exec(
  178. 'INSERT INTO ' . self::_sanitizeIdentifier('paste') .
  179. ' VALUES(?,?,?,?,?,?,?,?,?)',
  180. array(
  181. $pasteid,
  182. $paste['data'],
  183. $paste['meta']['postdate'],
  184. $expire_date,
  185. (int) $opendiscussion,
  186. (int) $burnafterreading,
  187. json_encode($meta),
  188. $attachment,
  189. $attachmentname,
  190. )
  191. );
  192. }
  193. /**
  194. * Read a paste.
  195. *
  196. * @access public
  197. * @param string $pasteid
  198. * @return stdClass|false
  199. */
  200. public function read($pasteid)
  201. {
  202. if (
  203. !array_key_exists($pasteid, self::$_cache)
  204. ) {
  205. self::$_cache[$pasteid] = false;
  206. $paste = self::_select(
  207. 'SELECT * FROM ' . self::_sanitizeIdentifier('paste') .
  208. ' WHERE dataid = ?', array($pasteid), true
  209. );
  210. if (false !== $paste) {
  211. // create object
  212. self::$_cache[$pasteid] = new stdClass;
  213. self::$_cache[$pasteid]->data = $paste['data'];
  214. $meta = json_decode($paste['meta']);
  215. if (!is_object($meta)) {
  216. $meta = new stdClass;
  217. }
  218. // support older attachments
  219. if (property_exists($meta, 'attachment')) {
  220. self::$_cache[$pasteid]->attachment = $meta->attachment;
  221. unset($meta->attachment);
  222. if (property_exists($meta, 'attachmentname')) {
  223. self::$_cache[$pasteid]->attachmentname = $meta->attachmentname;
  224. unset($meta->attachmentname);
  225. }
  226. }
  227. // support current attachments
  228. elseif (array_key_exists('attachment', $paste) && strlen($paste['attachment'])) {
  229. self::$_cache[$pasteid]->attachment = $paste['attachment'];
  230. if (array_key_exists('attachmentname', $paste) && strlen($paste['attachmentname'])) {
  231. self::$_cache[$pasteid]->attachmentname = $paste['attachmentname'];
  232. }
  233. }
  234. self::$_cache[$pasteid]->meta = $meta;
  235. self::$_cache[$pasteid]->meta->postdate = (int) $paste['postdate'];
  236. $expire_date = (int) $paste['expiredate'];
  237. if (
  238. $expire_date > 0
  239. ) {
  240. self::$_cache[$pasteid]->meta->expire_date = $expire_date;
  241. }
  242. if (
  243. $paste['opendiscussion']
  244. ) {
  245. self::$_cache[$pasteid]->meta->opendiscussion = true;
  246. }
  247. if (
  248. $paste['burnafterreading']
  249. ) {
  250. self::$_cache[$pasteid]->meta->burnafterreading = true;
  251. }
  252. }
  253. }
  254. return self::$_cache[$pasteid];
  255. }
  256. /**
  257. * Delete a paste and its discussion.
  258. *
  259. * @access public
  260. * @param string $pasteid
  261. */
  262. public function delete($pasteid)
  263. {
  264. self::_exec(
  265. 'DELETE FROM ' . self::_sanitizeIdentifier('paste') .
  266. ' WHERE dataid = ?', array($pasteid)
  267. );
  268. self::_exec(
  269. 'DELETE FROM ' . self::_sanitizeIdentifier('comment') .
  270. ' WHERE pasteid = ?', array($pasteid)
  271. );
  272. if (
  273. array_key_exists($pasteid, self::$_cache)
  274. ) {
  275. unset(self::$_cache[$pasteid]);
  276. }
  277. }
  278. /**
  279. * Test if a paste exists.
  280. *
  281. * @access public
  282. * @param string $pasteid
  283. * @return bool
  284. */
  285. public function exists($pasteid)
  286. {
  287. if (
  288. !array_key_exists($pasteid, self::$_cache)
  289. ) {
  290. self::$_cache[$pasteid] = $this->read($pasteid);
  291. }
  292. return (bool) self::$_cache[$pasteid];
  293. }
  294. /**
  295. * Create a comment in a paste.
  296. *
  297. * @access public
  298. * @param string $pasteid
  299. * @param string $parentid
  300. * @param string $commentid
  301. * @param array $comment
  302. * @return bool
  303. */
  304. public function createComment($pasteid, $parentid, $commentid, $comment)
  305. {
  306. foreach (array('nickname', 'vizhash') as $key) {
  307. if (!array_key_exists($key, $comment['meta'])) {
  308. $comment['meta'][$key] = null;
  309. }
  310. }
  311. return self::_exec(
  312. 'INSERT INTO ' . self::_sanitizeIdentifier('comment') .
  313. ' VALUES(?,?,?,?,?,?,?)',
  314. array(
  315. $commentid,
  316. $pasteid,
  317. $parentid,
  318. $comment['data'],
  319. $comment['meta']['nickname'],
  320. $comment['meta']['vizhash'],
  321. $comment['meta']['postdate'],
  322. )
  323. );
  324. }
  325. /**
  326. * Read all comments of paste.
  327. *
  328. * @access public
  329. * @param string $pasteid
  330. * @return array
  331. */
  332. public function readComments($pasteid)
  333. {
  334. $rows = self::_select(
  335. 'SELECT * FROM ' . self::_sanitizeIdentifier('comment') .
  336. ' WHERE pasteid = ?', array($pasteid)
  337. );
  338. // create comment list
  339. $comments = array();
  340. if (count($rows)) {
  341. foreach ($rows as $row) {
  342. $i = $this->getOpenSlot($comments, (int) $row['postdate']);
  343. $comments[$i] = new stdClass;
  344. $comments[$i]->id = $row['dataid'];
  345. $comments[$i]->parentid = $row['parentid'];
  346. $comments[$i]->data = $row['data'];
  347. $comments[$i]->meta = new stdClass;
  348. $comments[$i]->meta->postdate = (int) $row['postdate'];
  349. foreach (array('nickname', 'vizhash') as $key) {
  350. if (array_key_exists($key, $row) && !empty($row[$key])) {
  351. $comments[$i]->meta->$key = $row[$key];
  352. }
  353. }
  354. }
  355. ksort($comments);
  356. }
  357. return $comments;
  358. }
  359. /**
  360. * Test if a comment exists.
  361. *
  362. * @access public
  363. * @param string $pasteid
  364. * @param string $parentid
  365. * @param string $commentid
  366. * @return bool
  367. */
  368. public function existsComment($pasteid, $parentid, $commentid)
  369. {
  370. return (bool) self::_select(
  371. 'SELECT dataid FROM ' . self::_sanitizeIdentifier('comment') .
  372. ' WHERE pasteid = ? AND parentid = ? AND dataid = ?',
  373. array($pasteid, $parentid, $commentid), true
  374. );
  375. }
  376. /**
  377. * Returns up to batch size number of paste ids that have expired
  378. *
  379. * @access private
  380. * @param int $batchsize
  381. * @return array
  382. */
  383. protected function _getExpiredPastes($batchsize)
  384. {
  385. $pastes = array();
  386. $rows = self::_select(
  387. 'SELECT dataid FROM ' . self::_sanitizeIdentifier('paste') .
  388. ' WHERE expiredate < ? AND expiredate != ? LIMIT ?', array(time(), 0, $batchsize)
  389. );
  390. if (count($rows)) {
  391. foreach ($rows as $row) {
  392. $pastes[] = $row['dataid'];
  393. }
  394. }
  395. return $pastes;
  396. }
  397. /**
  398. * execute a statement
  399. *
  400. * @access private
  401. * @static
  402. * @param string $sql
  403. * @param array $params
  404. * @throws PDOException
  405. * @return bool
  406. */
  407. private static function _exec($sql, array $params)
  408. {
  409. $statement = self::$_db->prepare($sql);
  410. $result = $statement->execute($params);
  411. $statement->closeCursor();
  412. return $result;
  413. }
  414. /**
  415. * run a select statement
  416. *
  417. * @access private
  418. * @static
  419. * @param string $sql
  420. * @param array $params
  421. * @param bool $firstOnly if only the first row should be returned
  422. * @throws PDOException
  423. * @return array
  424. */
  425. private static function _select($sql, array $params, $firstOnly = false)
  426. {
  427. $statement = self::$_db->prepare($sql);
  428. $statement->execute($params);
  429. $result = $firstOnly ?
  430. $statement->fetch(PDO::FETCH_ASSOC) :
  431. $statement->fetchAll(PDO::FETCH_ASSOC);
  432. $statement->closeCursor();
  433. return $result;
  434. }
  435. /**
  436. * get table list query, depending on the database type
  437. *
  438. * @access private
  439. * @static
  440. * @param string $type
  441. * @throws Exception
  442. * @return string
  443. */
  444. private static function _getTableQuery($type)
  445. {
  446. switch ($type) {
  447. case 'ibm':
  448. $sql = 'SELECT tabname FROM SYSCAT.TABLES ';
  449. break;
  450. case 'informix':
  451. $sql = 'SELECT tabname FROM systables ';
  452. break;
  453. case 'mssql':
  454. $sql = 'SELECT name FROM sysobjects '
  455. . "WHERE type = 'U' ORDER BY name";
  456. break;
  457. case 'mysql':
  458. $sql = 'SHOW TABLES';
  459. break;
  460. case 'oci':
  461. $sql = 'SELECT table_name FROM all_tables';
  462. break;
  463. case 'pgsql':
  464. $sql = 'SELECT c.relname AS table_name '
  465. . 'FROM pg_class c, pg_user u '
  466. . "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
  467. . 'AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) '
  468. . "AND c.relname !~ '^(pg_|sql_)' "
  469. . 'UNION '
  470. . 'SELECT c.relname AS table_name '
  471. . 'FROM pg_class c '
  472. . "WHERE c.relkind = 'r' "
  473. . 'AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) '
  474. . 'AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) '
  475. . "AND c.relname !~ '^pg_'";
  476. break;
  477. case 'sqlite':
  478. $sql = "SELECT name FROM sqlite_master WHERE type='table' "
  479. . 'UNION ALL SELECT name FROM sqlite_temp_master '
  480. . "WHERE type='table' ORDER BY name";
  481. break;
  482. default:
  483. throw new Exception(
  484. "PDO type $type is currently not supported.", 5
  485. );
  486. }
  487. return $sql;
  488. }
  489. /**
  490. * get a value by key from the config table
  491. *
  492. * @access private
  493. * @static
  494. * @param string $key
  495. * @throws PDOException
  496. * @return string
  497. */
  498. private static function _getConfig($key)
  499. {
  500. $row = self::_select(
  501. 'SELECT value FROM ' . self::_sanitizeIdentifier('config') .
  502. ' WHERE id = ?', array($key), true
  503. );
  504. return $row['value'];
  505. }
  506. /**
  507. * get the primary key clauses, depending on the database driver
  508. *
  509. * @access private
  510. * @static
  511. * @param string $key
  512. * @return array
  513. */
  514. private static function _getPrimaryKeyClauses($key = 'dataid')
  515. {
  516. $main_key = $after_key = '';
  517. if (self::$_type === 'mysql') {
  518. $after_key = ", PRIMARY KEY ($key)";
  519. } else {
  520. $main_key = ' PRIMARY KEY';
  521. }
  522. return array($main_key, $after_key);
  523. }
  524. /**
  525. * get the data type, depending on the database driver
  526. *
  527. * @access private
  528. * @static
  529. * @return string
  530. */
  531. private static function _getDataType()
  532. {
  533. return self::$_type === 'pgsql' ? 'TEXT' : 'BLOB';
  534. }
  535. /**
  536. * get the attachment type, depending on the database driver
  537. *
  538. * @access private
  539. * @static
  540. * @return string
  541. */
  542. private static function _getAttachmentType()
  543. {
  544. return self::$_type === 'pgsql' ? 'TEXT' : 'MEDIUMBLOB';
  545. }
  546. /**
  547. * create the paste table
  548. *
  549. * @access private
  550. * @static
  551. */
  552. private static function _createPasteTable()
  553. {
  554. list($main_key, $after_key) = self::_getPrimaryKeyClauses();
  555. $dataType = self::_getDataType();
  556. self::$_db->exec(
  557. 'CREATE TABLE ' . self::_sanitizeIdentifier('paste') . ' ( ' .
  558. "dataid CHAR(16) NOT NULL$main_key, " .
  559. "data $dataType, " .
  560. 'postdate INT, ' .
  561. 'expiredate INT, ' .
  562. 'opendiscussion INT, ' .
  563. 'burnafterreading INT, ' .
  564. 'meta TEXT, ' .
  565. 'attachment ' . self::_getAttachmentType() . ', ' .
  566. "attachmentname $dataType$after_key );"
  567. );
  568. }
  569. /**
  570. * create the paste table
  571. *
  572. * @access private
  573. * @static
  574. */
  575. private static function _createCommentTable()
  576. {
  577. list($main_key, $after_key) = self::_getPrimaryKeyClauses();
  578. $dataType = self::_getDataType();
  579. self::$_db->exec(
  580. 'CREATE TABLE ' . self::_sanitizeIdentifier('comment') . ' ( ' .
  581. "dataid CHAR(16) NOT NULL$main_key, " .
  582. 'pasteid CHAR(16), ' .
  583. 'parentid CHAR(16), ' .
  584. "data $dataType, " .
  585. "nickname $dataType, " .
  586. "vizhash $dataType, " .
  587. "postdate INT$after_key );"
  588. );
  589. self::$_db->exec(
  590. 'CREATE INDEX IF NOT EXISTS comment_parent ON ' .
  591. self::_sanitizeIdentifier('comment') . '(pasteid);'
  592. );
  593. }
  594. /**
  595. * create the paste table
  596. *
  597. * @access private
  598. * @static
  599. */
  600. private static function _createConfigTable()
  601. {
  602. list($main_key, $after_key) = self::_getPrimaryKeyClauses('id');
  603. self::$_db->exec(
  604. 'CREATE TABLE ' . self::_sanitizeIdentifier('config') .
  605. " ( id CHAR(16) NOT NULL$main_key, value TEXT$after_key );"
  606. );
  607. self::_exec(
  608. 'INSERT INTO ' . self::_sanitizeIdentifier('config') .
  609. ' VALUES(?,?)',
  610. array('VERSION', Controller::VERSION)
  611. );
  612. }
  613. /**
  614. * sanitizes identifiers
  615. *
  616. * @access private
  617. * @static
  618. * @param string $identifier
  619. * @return string
  620. */
  621. private static function _sanitizeIdentifier($identifier)
  622. {
  623. return preg_replace('/[^A-Za-z0-9_]+/', '', self::$_prefix . $identifier);
  624. }
  625. /**
  626. * upgrade the database schema from an old version
  627. *
  628. * @access private
  629. * @static
  630. * @param string $oldversion
  631. */
  632. private static function _upgradeDatabase($oldversion)
  633. {
  634. $dataType = self::_getDataType();
  635. switch ($oldversion) {
  636. case '0.21':
  637. // create the meta column if necessary (pre 0.21 change)
  638. try {
  639. self::$_db->exec('SELECT meta FROM ' . self::_sanitizeIdentifier('paste') . ' LIMIT 1;');
  640. } catch (PDOException $e) {
  641. self::$_db->exec('ALTER TABLE ' . self::_sanitizeIdentifier('paste') . ' ADD COLUMN meta TEXT;');
  642. }
  643. // SQLite only allows one ALTER statement at a time...
  644. self::$_db->exec(
  645. 'ALTER TABLE ' . self::_sanitizeIdentifier('paste') .
  646. ' ADD COLUMN attachment ' . self::_getAttachmentType() . ';'
  647. );
  648. self::$_db->exec(
  649. 'ALTER TABLE ' . self::_sanitizeIdentifier('paste') . " ADD COLUMN attachmentname $dataType;"
  650. );
  651. // SQLite doesn't support MODIFY, but it allows TEXT of similar
  652. // size as BLOB, so there is no need to change it there
  653. if (self::$_type !== 'sqlite') {
  654. self::$_db->exec(
  655. 'ALTER TABLE ' . self::_sanitizeIdentifier('paste') .
  656. ' ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType;'
  657. );
  658. self::$_db->exec(
  659. 'ALTER TABLE ' . self::_sanitizeIdentifier('comment') .
  660. " ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType, " .
  661. "MODIFY COLUMN nickname $dataType, MODIFY COLUMN vizhash $dataType;"
  662. );
  663. } else {
  664. self::$_db->exec(
  665. 'CREATE UNIQUE INDEX IF NOT EXISTS paste_dataid ON ' .
  666. self::_sanitizeIdentifier('paste') . '(dataid);'
  667. );
  668. self::$_db->exec(
  669. 'CREATE UNIQUE INDEX IF NOT EXISTS comment_dataid ON ' .
  670. self::_sanitizeIdentifier('comment') . '(dataid);'
  671. );
  672. }
  673. self::$_db->exec(
  674. 'CREATE INDEX IF NOT EXISTS comment_parent ON ' .
  675. self::_sanitizeIdentifier('comment') . '(pasteid);'
  676. );
  677. // no break, continue with updates for 0.22 and later
  678. default:
  679. self::_exec(
  680. 'UPDATE ' . self::_sanitizeIdentifier('config') .
  681. ' SET value = ? WHERE id = ?',
  682. array(Controller::VERSION, 'VERSION')
  683. );
  684. }
  685. }
  686. }