found and resolved issues in database layer, thanks to report in #42

This commit is contained in:
El RIDO 2015-10-16 23:13:36 +02:00
parent 87b41a0c3d
commit b92b38cee8
3 changed files with 15 additions and 17 deletions

View File

@ -340,10 +340,7 @@ class zerobin
if ($paste->exists())
{
// The paste itself is the first in the list of encrypted messages.
$messages = array_merge(
array($paste->get()),
$paste->getComments()
);
$messages = array_merge(array($paste->get()), $paste->getComments());
$this->_data = json_encode($messages);
}
else

View File

@ -138,7 +138,7 @@ abstract class zerobin_abstract
$parts = explode('.', $postdate, 2);
if (!array_key_exists(1, $parts)) $parts[1] = 0;
++$parts[1];
return $this->addComment($comments, implode('.', $parts));
return $this->getOpenSlot($comments, implode('.', $parts));
}
return $postdate;
}

View File

@ -80,6 +80,11 @@ class zerobin_db extends zerobin_abstract
array_key_exists('opt', $options)
)
{
// set default options
$options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$options['opt'][PDO::ATTR_EMULATE_PREPARES] = false;
$options['opt'][PDO::ATTR_PERSISTENT] = true;
// check if the database contains the required tables
self::$_type = strtolower(
substr($options['dsn'], 0, strpos($options['dsn'], ':'))
@ -156,14 +161,11 @@ class zerobin_db extends zerobin_abstract
else
{
try {
self::$_db->exec('SELECT meta FROM ' . self::$_prefix . 'paste LIMIT 1;');
self::_exec('SELECT meta FROM ' . self::$_prefix . 'paste LIMIT 1;', array());
} catch (PDOException $e) {
if ($e->getCode() == 'HY000')
{
self::$_db->exec('ALTER TABLE ' . self::$_prefix . 'paste ADD COLUMN meta TEXT;');
}
}
}
// create comment table if needed
if (!in_array(self::$_prefix . 'comment', $tables))
@ -368,10 +370,6 @@ class zerobin_db extends zerobin_abstract
array($pasteid)
);
// create object
$commentTemplate = new stdClass;
$commentTemplate->meta = new stdClass;
// create comment list
$comments = array();
if (count($rows))
@ -379,9 +377,12 @@ class zerobin_db extends zerobin_abstract
foreach ($rows as $row)
{
$i = $this->getOpenSlot($comments, (int) $row['postdate']);
$comments[$i] = clone $commentTemplate;
$comments[$i] = new stdClass;
$comments[$i]->data = $row['data'];
$comments[$i]->meta = new stdClass;
if (array_key_exists('nickname', $row))
$comments[$i]->meta->nickname = $row['nickname'];
if (array_key_exists('vizhash', $row))
$comments[$i]->meta->vizhash = $row['vizhash'];
$comments[$i]->meta->postdate = $i;
$comments[$i]->meta->commentid = $row['dataid'];