|
@@ -143,48 +143,20 @@ class Database extends AbstractData
|
|
|
public function create($pasteid, array &$paste)
|
|
public function create($pasteid, array &$paste)
|
|
|
{
|
|
{
|
|
|
$expire_date = 0;
|
|
$expire_date = 0;
|
|
|
- $opendiscussion = $burnafterreading = false;
|
|
|
|
|
- $attachment = $attachmentname = null;
|
|
|
|
|
$meta = $paste['meta'];
|
|
$meta = $paste['meta'];
|
|
|
- $isVersion1 = array_key_exists('data', $paste);
|
|
|
|
|
if (array_key_exists('expire_date', $meta)) {
|
|
if (array_key_exists('expire_date', $meta)) {
|
|
|
$expire_date = (int) $meta['expire_date'];
|
|
$expire_date = (int) $meta['expire_date'];
|
|
|
unset($meta['expire_date']);
|
|
unset($meta['expire_date']);
|
|
|
}
|
|
}
|
|
|
- if (array_key_exists('opendiscussion', $meta)) {
|
|
|
|
|
- $opendiscussion = $meta['opendiscussion'];
|
|
|
|
|
- unset($meta['opendiscussion']);
|
|
|
|
|
- }
|
|
|
|
|
- if (array_key_exists('burnafterreading', $meta)) {
|
|
|
|
|
- $burnafterreading = $meta['burnafterreading'];
|
|
|
|
|
- unset($meta['burnafterreading']);
|
|
|
|
|
- }
|
|
|
|
|
- if ($isVersion1) {
|
|
|
|
|
- if (array_key_exists('attachment', $meta)) {
|
|
|
|
|
- $attachment = $meta['attachment'];
|
|
|
|
|
- unset($meta['attachment']);
|
|
|
|
|
- }
|
|
|
|
|
- if (array_key_exists('attachmentname', $meta)) {
|
|
|
|
|
- $attachmentname = $meta['attachmentname'];
|
|
|
|
|
- unset($meta['attachmentname']);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- $opendiscussion = $paste['adata'][2];
|
|
|
|
|
- $burnafterreading = $paste['adata'][3];
|
|
|
|
|
- }
|
|
|
|
|
try {
|
|
try {
|
|
|
return $this->_exec(
|
|
return $this->_exec(
|
|
|
'INSERT INTO "' . $this->_sanitizeIdentifier('paste') .
|
|
'INSERT INTO "' . $this->_sanitizeIdentifier('paste') .
|
|
|
- '" VALUES(?,?,?,?,?,?,?,?)',
|
|
|
|
|
|
|
+ '" VALUES(?,?,?,?)',
|
|
|
array(
|
|
array(
|
|
|
$pasteid,
|
|
$pasteid,
|
|
|
- $isVersion1 ? $paste['data'] : Json::encode($paste),
|
|
|
|
|
|
|
+ Json::encode($paste),
|
|
|
$expire_date,
|
|
$expire_date,
|
|
|
- (int) $opendiscussion,
|
|
|
|
|
- (int) $burnafterreading,
|
|
|
|
|
Json::encode($meta),
|
|
Json::encode($meta),
|
|
|
- $attachment,
|
|
|
|
|
- $attachmentname,
|
|
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
@@ -213,38 +185,17 @@ class Database extends AbstractData
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
// create array
|
|
// create array
|
|
|
- $data = Json::decode($row['data']);
|
|
|
|
|
- $isVersion2 = array_key_exists('v', $data) && $data['v'] >= 2;
|
|
|
|
|
- $paste = $isVersion2 ? $data : array('data' => $row['data']);
|
|
|
|
|
|
|
+ $paste = Json::decode($row['data']);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- $row['meta'] = Json::decode($row['meta']);
|
|
|
|
|
|
|
+ $paste['meta'] = Json::decode($row['meta']);
|
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
|
- $row['meta'] = array();
|
|
|
|
|
|
|
+ $paste['meta'] = array();
|
|
|
}
|
|
}
|
|
|
- $row = self::upgradePreV1Format($row);
|
|
|
|
|
- $paste['meta'] = $row['meta'];
|
|
|
|
|
- $expire_date = (int) $row['expiredate'];
|
|
|
|
|
|
|
+ $expire_date = (int) $row['expiredate'];
|
|
|
if ($expire_date > 0) {
|
|
if ($expire_date > 0) {
|
|
|
$paste['meta']['expire_date'] = $expire_date;
|
|
$paste['meta']['expire_date'] = $expire_date;
|
|
|
}
|
|
}
|
|
|
- if ($isVersion2) {
|
|
|
|
|
- return $paste;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // support v1 attachments
|
|
|
|
|
- if (array_key_exists('attachment', $row) && !empty($row['attachment'])) {
|
|
|
|
|
- $paste['attachment'] = $row['attachment'];
|
|
|
|
|
- if (array_key_exists('attachmentname', $row) && !empty($row['attachmentname'])) {
|
|
|
|
|
- $paste['attachmentname'] = $row['attachmentname'];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if ($row['opendiscussion']) {
|
|
|
|
|
- $paste['meta']['opendiscussion'] = true;
|
|
|
|
|
- }
|
|
|
|
|
- if ($row['burnafterreading']) {
|
|
|
|
|
- $paste['meta']['burnafterreading'] = true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
return $paste;
|
|
return $paste;
|
|
|
}
|
|
}
|
|
@@ -299,21 +250,14 @@ class Database extends AbstractData
|
|
|
*/
|
|
*/
|
|
|
public function createComment($pasteid, $parentid, $commentid, array &$comment)
|
|
public function createComment($pasteid, $parentid, $commentid, array &$comment)
|
|
|
{
|
|
{
|
|
|
- if (array_key_exists('data', $comment)) {
|
|
|
|
|
- $version = 1;
|
|
|
|
|
- $data = $comment['data'];
|
|
|
|
|
- } else {
|
|
|
|
|
- try {
|
|
|
|
|
- $version = 2;
|
|
|
|
|
- $data = Json::encode($comment);
|
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ $data = Json::encode($comment);
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- list($createdKey, $iconKey) = $this->_getVersionedKeys($version);
|
|
|
|
|
- $meta = $comment['meta'];
|
|
|
|
|
|
|
+ $meta = $comment['meta'];
|
|
|
unset($comment['meta']);
|
|
unset($comment['meta']);
|
|
|
- foreach (array('nickname', $iconKey) as $key) {
|
|
|
|
|
|
|
+ foreach (array('nickname', 'icon') as $key) {
|
|
|
if (!array_key_exists($key, $meta)) {
|
|
if (!array_key_exists($key, $meta)) {
|
|
|
$meta[$key] = null;
|
|
$meta[$key] = null;
|
|
|
}
|
|
}
|
|
@@ -328,8 +272,8 @@ class Database extends AbstractData
|
|
|
$parentid,
|
|
$parentid,
|
|
|
$data,
|
|
$data,
|
|
|
$meta['nickname'],
|
|
$meta['nickname'],
|
|
|
- $meta[$iconKey],
|
|
|
|
|
- $meta[$createdKey],
|
|
|
|
|
|
|
+ $meta['icon'],
|
|
|
|
|
+ $meta['created'],
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
@@ -355,20 +299,12 @@ class Database extends AbstractData
|
|
|
$comments = array();
|
|
$comments = array();
|
|
|
if (is_array($rows) && count($rows)) {
|
|
if (is_array($rows) && count($rows)) {
|
|
|
foreach ($rows as $row) {
|
|
foreach ($rows as $row) {
|
|
|
- $i = $this->getOpenSlot($comments, (int) $row['postdate']);
|
|
|
|
|
- $data = Json::decode($row['data']);
|
|
|
|
|
- if (array_key_exists('v', $data) && $data['v'] >= 2) {
|
|
|
|
|
- $version = 2;
|
|
|
|
|
- $comments[$i] = $data;
|
|
|
|
|
- } else {
|
|
|
|
|
- $version = 1;
|
|
|
|
|
- $comments[$i] = array('data' => $row['data']);
|
|
|
|
|
- }
|
|
|
|
|
- list($createdKey, $iconKey) = $this->_getVersionedKeys($version);
|
|
|
|
|
|
|
+ $i = $this->getOpenSlot($comments, (int) $row['postdate']);
|
|
|
|
|
+ $comments[$i] = Json::decode($row['data']);
|
|
|
$comments[$i]['id'] = $row['dataid'];
|
|
$comments[$i]['id'] = $row['dataid'];
|
|
|
$comments[$i]['parentid'] = $row['parentid'];
|
|
$comments[$i]['parentid'] = $row['parentid'];
|
|
|
- $comments[$i]['meta'] = array($createdKey => (int) $row['postdate']);
|
|
|
|
|
- foreach (array('nickname' => 'nickname', 'vizhash' => $iconKey) as $rowKey => $commentKey) {
|
|
|
|
|
|
|
+ $comments[$i]['meta'] = array('created' => (int) $row['postdate']);
|
|
|
|
|
+ foreach (array('nickname' => 'nickname', 'vizhash' => 'icon') as $rowKey => $commentKey) {
|
|
|
if (array_key_exists($rowKey, $row) && !empty($row[$rowKey])) {
|
|
if (array_key_exists($rowKey, $row) && !empty($row[$rowKey])) {
|
|
|
$comments[$i]['meta'][$commentKey] = $row[$rowKey];
|
|
$comments[$i]['meta'][$commentKey] = $row[$rowKey];
|
|
|
}
|
|
}
|
|
@@ -561,21 +497,6 @@ class Database extends AbstractData
|
|
|
return $result;
|
|
return $result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * get version dependent key names
|
|
|
|
|
- *
|
|
|
|
|
- * @access private
|
|
|
|
|
- * @param int $version
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- private function _getVersionedKeys($version)
|
|
|
|
|
- {
|
|
|
|
|
- if ($version === 1) {
|
|
|
|
|
- return array('postdate', 'vizhash');
|
|
|
|
|
- }
|
|
|
|
|
- return array('created', 'icon');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* get table list query, depending on the database type
|
|
* get table list query, depending on the database type
|
|
|
*
|
|
*
|
|
@@ -737,16 +658,12 @@ class Database extends AbstractData
|
|
|
"\"dataid\" CHAR(16) NOT NULL$main_key, " .
|
|
"\"dataid\" CHAR(16) NOT NULL$main_key, " .
|
|
|
"\"data\" $attachmentType, " .
|
|
"\"data\" $attachmentType, " .
|
|
|
'"expiredate" INT, ' .
|
|
'"expiredate" INT, ' .
|
|
|
- '"opendiscussion" INT, ' .
|
|
|
|
|
- '"burnafterreading" INT, ' .
|
|
|
|
|
- "\"meta\" $metaType, " .
|
|
|
|
|
- "\"attachment\" $attachmentType, " .
|
|
|
|
|
- "\"attachmentname\" $dataType$after_key )"
|
|
|
|
|
|
|
+ "\"meta\" $metaType$after_key )"
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * create the paste table
|
|
|
|
|
|
|
+ * create the comment table
|
|
|
*
|
|
*
|
|
|
* @access private
|
|
* @access private
|
|
|
*/
|
|
*/
|
|
@@ -789,7 +706,7 @@ class Database extends AbstractData
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * create the paste table
|
|
|
|
|
|
|
+ * create the config table
|
|
|
*
|
|
*
|
|
|
* @access private
|
|
* @access private
|
|
|
*/
|
|
*/
|
|
@@ -839,6 +756,26 @@ class Database extends AbstractData
|
|
|
return preg_replace('/[^A-Za-z0-9_]+/', '', $this->_prefix . $identifier);
|
|
return preg_replace('/[^A-Za-z0-9_]+/', '', $this->_prefix . $identifier);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * check if the current database type supports dropping columns
|
|
|
|
|
+ *
|
|
|
|
|
+ * @access private
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
|
|
+ private function _supportsDropColumn()
|
|
|
|
|
+ {
|
|
|
|
|
+ $supportsDropColumn = true;
|
|
|
|
|
+ if ($this->_type === 'sqlite') {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $row = $this->_select('SELECT sqlite_version() AS "v"', array(), true);
|
|
|
|
|
+ $supportsDropColumn = version_compare($row['v'], '3.35.0', '>=');
|
|
|
|
|
+ } catch (PDOException $e) {
|
|
|
|
|
+ $supportsDropColumn = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $supportsDropColumn;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* upgrade the database schema from an old version
|
|
* upgrade the database schema from an old version
|
|
|
*
|
|
*
|
|
@@ -910,22 +847,33 @@ class Database extends AbstractData
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (version_compare($oldversion, '1.7.1', '<=')) {
|
|
if (version_compare($oldversion, '1.7.1', '<=')) {
|
|
|
- $supportsDropColumn = true;
|
|
|
|
|
- if ($this->_type === 'sqlite') {
|
|
|
|
|
- try {
|
|
|
|
|
- $row = $this->_select('SELECT sqlite_version() AS "v"', array(), true);
|
|
|
|
|
- $supportsDropColumn = version_compare($row['v'], '3.35.0', '>=');
|
|
|
|
|
- } catch (PDOException $e) {
|
|
|
|
|
- $supportsDropColumn = false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if ($supportsDropColumn) {
|
|
|
|
|
|
|
+ if ($this->_supportsDropColumn()) {
|
|
|
$this->_db->exec(
|
|
$this->_db->exec(
|
|
|
'ALTER TABLE "' . $this->_sanitizeIdentifier('paste') .
|
|
'ALTER TABLE "' . $this->_sanitizeIdentifier('paste') .
|
|
|
'" DROP COLUMN "postdate"'
|
|
'" DROP COLUMN "postdate"'
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (version_compare($oldversion, '1.7.8', '<=')) {
|
|
|
|
|
+ if ($this->_supportsDropColumn()) {
|
|
|
|
|
+ $this->_db->exec(
|
|
|
|
|
+ 'ALTER TABLE "' . $this->_sanitizeIdentifier('paste') .
|
|
|
|
|
+ '" DROP COLUMN "opendiscussion"'
|
|
|
|
|
+ );
|
|
|
|
|
+ $this->_db->exec(
|
|
|
|
|
+ 'ALTER TABLE "' . $this->_sanitizeIdentifier('paste') .
|
|
|
|
|
+ '" DROP COLUMN "burnafterreading"'
|
|
|
|
|
+ );
|
|
|
|
|
+ $this->_db->exec(
|
|
|
|
|
+ 'ALTER TABLE "' . $this->_sanitizeIdentifier('paste') .
|
|
|
|
|
+ '" DROP COLUMN "attachment"'
|
|
|
|
|
+ );
|
|
|
|
|
+ $this->_db->exec(
|
|
|
|
|
+ 'ALTER TABLE "' . $this->_sanitizeIdentifier('paste') .
|
|
|
|
|
+ '" DROP COLUMN "attachmentname"'
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
$this->_exec(
|
|
$this->_exec(
|
|
|
'UPDATE "' . $this->_sanitizeIdentifier('config') .
|
|
'UPDATE "' . $this->_sanitizeIdentifier('config') .
|
|
|
'" SET "value" = ? WHERE "id" = ?',
|
|
'" SET "value" = ? WHERE "id" = ?',
|