Explorar el Código

remove more v1 remnants

kudos @Ribas160
El RIDO hace 1 año
padre
commit
c99e6895dd
Se han modificado 4 ficheros con 22 adiciones y 23 borrados
  1. 11 6
      lib/Data/AbstractData.php
  2. 1 3
      lib/Data/Filesystem.php
  3. 4 8
      lib/Model/Paste.php
  4. 6 6
      tst/Data/DatabaseTest.php

+ 11 - 6
lib/Data/AbstractData.php

@@ -171,23 +171,28 @@ abstract class AbstractData
     abstract public function getAllPastes();
 
     /**
-     * Get next free slot for comment from postdate.
+     * Get next free slot for comment from the creation timestamp
+     *
+     * The creation timestamp is usually a unix timestamp in seconds, but if a
+     * comment already exists at that timestamp, a number, separated by a dot is
+     * appended to it and incremented, then the function recurses until a free
+     * slot is found.
      *
      * @access protected
      * @param  array $comments
-     * @param  int|string $postdate
+     * @param  int|string $created
      * @return int|string
      */
-    protected function getOpenSlot(array &$comments, $postdate)
+    protected function getOpenSlot(array &$comments, $created)
     {
-        if (array_key_exists($postdate, $comments)) {
-            $parts = explode('.', (string) $postdate, 2);
+        if (array_key_exists($created, $comments)) {
+            $parts = explode('.', (string) $created, 2);
             if (!array_key_exists(1, $parts)) {
                 $parts[1] = 0;
             }
             ++$parts[1];
             return $this->getOpenSlot($comments, implode('.', $parts));
         }
-        return $postdate;
+        return $created;
     }
 }

+ 1 - 3
lib/Data/Filesystem.php

@@ -229,9 +229,7 @@ class Filesystem extends AbstractData
                     // Store in array
                     $key            = $this->getOpenSlot(
                         $comments,
-                        (int) array_key_exists('created', $comment['meta']) ?
-                        $comment['meta']['created'] : // v2 comments
-                        $comment['meta']['postdate']  // v1 comments
+                        $comment['meta']['created']
                     );
                     $comments[$key] = $comment;
                 }

+ 4 - 8
lib/Model/Paste.php

@@ -68,10 +68,8 @@ class Paste extends AbstractModel
             $data['meta']['time_to_live'] = $data['meta']['expire_date'] - $now;
             unset($data['meta']['expire_date']);
         }
-        foreach (array('created', 'postdate') as $key) {
-            if (array_key_exists($key, $data['meta'])) {
-                unset($data['meta'][$key]);
-            }
+        if (array_key_exists('created', $data['meta'])) {
+            unset($data['meta']['created']);
         }
 
         // check if non-expired burn after reading paste needs to be deleted
@@ -188,10 +186,8 @@ class Paste extends AbstractModel
             return $this->_store->readComments($this->getId());
         }
         return array_map(function ($comment) {
-            foreach (array('created', 'postdate') as $key) {
-                if (array_key_exists($key, $comment['meta'])) {
-                    unset($comment['meta'][$key]);
-                }
+            if (array_key_exists('created', $comment['meta'])) {
+                unset($comment['meta']['created']);
             }
             return $comment;
         }, $this->_store->readComments($this->getId()));

+ 6 - 6
tst/Data/DatabaseTest.php

@@ -67,12 +67,12 @@ class DatabaseTest extends TestCase
         $comment2             = Helper::getComment();
         $meta1                = $comment1['meta'];
         $meta2                = $comment2['meta'];
-        $this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'v1 comment does not yet exist');
-        $this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), $comment1) !== false, 'store v1 comment');
-        $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'v1 comment exists after storing it');
-        $this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId()), 'v2 comment does not yet exist');
-        $this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId(), $comment2) !== false, 'store v2 comment');
-        $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId()), 'v2 comment exists after storing it');
+        $this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment 1 does not yet exist');
+        $this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), $comment1) !== false, 'store comment 1');
+        $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment 2 exists after storing it');
+        $this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId()), 'comment 2 does not yet exist');
+        $this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId(), $comment2) !== false, 'store comment 2');
+        $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId()), 'comment 2 exists after storing it');
         $comment1['id']       = Helper::getCommentId();
         $comment1['parentid'] = Helper::getPasteId();
         $comment1['meta']     = $meta1;