Author: as
Date: Fri Oct  5 16:31:31 2007
New Revision: 6376

Log:
- Fixed issue #11413: The search flag is off by default for restore() and
  delete().

Modified:
    trunk/Cache/ChangeLog
    trunk/Cache/src/storage.php
    trunk/Cache/src/storage/apc/apc_array.php
    trunk/Cache/src/storage/file.php
    trunk/Cache/src/storage/memory.php
    trunk/Cache/tests/storage_file_test.php
    trunk/Cache/tests/storage_test.php

Modified: trunk/Cache/ChangeLog
==============================================================================
--- trunk/Cache/ChangeLog [iso-8859-1] (original)
+++ trunk/Cache/ChangeLog [iso-8859-1] Fri Oct  5 16:31:31 2007
@@ -8,6 +8,8 @@
   caching. Based on a patch from Grady Kuhnline.
 - Fixed issue #11181: A physical location is not required anymore for pure
   memory backends.
+- Fixed issue #11413: The search flag is off by default for restore() and
+  delete().
 
 
 1.2 - Monday 02 July 2007

Modified: trunk/Cache/src/storage.php
==============================================================================
--- trunk/Cache/src/storage.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage.php [iso-8859-1] Fri Oct  5 16:31:31 2007
@@ -170,8 +170,9 @@
      * @param string $id                        The item ID.
      * @param array(string=>string) $attributes Attributes that describe the 
      *                                          cached data.
-     * @param bool $search                       Wheather to search for items
-     *                                           if not found directly.
+     * @param bool $search                      Wheather to search for items
+     *                                          if not found directly. Default 
is
+     *                                          false.
      * 
      * @return mixed The cached data on success, otherwise false.
      *
@@ -181,7 +182,7 @@
      *         has been corrupted by external influences (file permission 
      *         change).
      */
-    abstract public function restore( $id, $attributes = array() );
+    abstract public function restore( $id, $attributes = array(), $search = 
false );
 
     /**
      * Delete data from the cache.
@@ -198,8 +199,9 @@
      * @param string $id                        The item ID.
      * @param array(string=>string) $attributes Attributes that describe the 
      *                                          cached data.
-     * @param bool $search                       Wheather to search for items
-     *                                           if not found directly.
+     * @param bool $search                      Wheather to search for items
+     *                                          if not found directly. Default 
is
+     *                                          false.
      *
      * @throws ezcBaseFilePermissionException
      *         If an already existsing cache file could not be unlinked. 
@@ -207,7 +209,7 @@
      *         has been corrupted by external influences (file permission 
      *         change).
      */
-    abstract public function delete( $id = null, $attributes = array() );
+    abstract public function delete( $id = null, $attributes = array(), 
$search = false );
 
     /**
     * Return the number of items in the cache matching a certain criteria.

Modified: trunk/Cache/src/storage/apc/apc_array.php
==============================================================================
--- trunk/Cache/src/storage/apc/apc_array.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage/apc/apc_array.php [iso-8859-1] Fri Oct  5 16:31:31 
2007
@@ -248,10 +248,11 @@
             if ( $search === true
                  && count( $files = $this->search( $id, $attributes ) ) === 1 )
             {
-                $filename = $files[0];
+                $filename = $files[0][2];
             }
             else
             {
+                // There are more elements found during search, so false is 
returned
                 return false;
             }
         }
@@ -342,7 +343,7 @@
      * @param array(string=>string) $attributes Attributes describing the data 
to restore
      * @param bool $search Wheather to search for items if not found directly
      */
-    public function delete( $id = null, $attributes = array(), $search = true )
+    public function delete( $id = null, $attributes = array(), $search = false 
)
     {
         // Generates the identifier
         $filename = $this->properties['location'] . $this->generateIdentifier( 
$id, $attributes );

Modified: trunk/Cache/src/storage/file.php
==============================================================================
--- trunk/Cache/src/storage/file.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage/file.php [iso-8859-1] Fri Oct  5 16:31:31 2007
@@ -205,7 +205,7 @@
      *         has been corrupted by external influences (file permission 
      *         change).
      */
-    public function restore( $id, $attributes = array(), $search = true )
+    public function restore( $id, $attributes = array(), $search = false )
     {
         $filename = $this->properties['location'] . $this->generateIdentifier( 
$id, $attributes );
         if ( file_exists( $filename ) === false ) 
@@ -258,7 +258,7 @@
      *         has been corrupted by external influences (file permission 
      *         change).
      */
-    public function delete( $id = null, $attributes = array(), $search = true )
+    public function delete( $id = null, $attributes = array(), $search = false 
)
     {
         $filename = $this->properties['location'] . $this->generateIdentifier( 
$id, $attributes );
         $delFiles = array();

Modified: trunk/Cache/src/storage/memory.php
==============================================================================
--- trunk/Cache/src/storage/memory.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage/memory.php [iso-8859-1] Fri Oct  5 16:31:31 2007
@@ -145,7 +145,7 @@
      * @param bool $search Wheather to search for items if not found directly
      * @return mixed The cached data on success, otherwise false
      */
-    public function restore( $id, $attributes = array(), $search = true )
+    public function restore( $id, $attributes = array(), $search = false )
     {
         // Generate the Identifier
         $identifier = $this->generateIdentifier( $id, $attributes );
@@ -166,8 +166,7 @@
         }
 
         // Makes sure a cache exists
-        if ( is_object( $this->registry[$location][$id][$identifier] )
-             && $this->registry[$location][$id][$identifier]->data === false )
+        if ( $this->registry[$location][$id][$identifier] === false )
         {
             if ( $search === true
                  && count( $identifiers = $this->search( $id, $attributes ) ) 
=== 1 )
@@ -177,6 +176,7 @@
             }
             else
             {
+                // There are more elements found during search, so false is 
returned
                 return false;
             }
         }
@@ -221,7 +221,7 @@
      * @param array(string=>string) $attributes Attributes describing the data 
to restore
      * @param bool $search Wheather to search for items if not found directly
      */
-    public function delete( $id = null, $attributes = array(), $search = true )
+    public function delete( $id = null, $attributes = array(), $search = false 
)
     {
         // Generate the Identifier
         $identifier = $this->generateIdentifier( $id, $attributes );
@@ -350,7 +350,6 @@
                 foreach ( $this->searchRegistry[$location] as $id => $arr )
                 {
                     foreach ( $arr as $identifier => $registryObj )
-                    //foreach ( $this->searchRegistry[$location][$id] as 
$identifier => $registryObj )
                     {
                         $attrStr = $this->generateAttrStr( 
$registryObj->attributes );
                         if ( preg_match( $pattern, $attrStr ) )

Modified: trunk/Cache/tests/storage_file_test.php
==============================================================================
--- trunk/Cache/tests/storage_file_test.php [iso-8859-1] (original)
+++ trunk/Cache/tests/storage_file_test.php [iso-8859-1] Fri Oct  5 16:31:31 
2007
@@ -110,7 +110,7 @@
         // Fake mtime and atime
         touch( $cache->getLocation() . '/' . $file, time() - 90000, time() - 
90000 );
         
-        $this->assertNotEquals( false, $cache->restore( 0 ) );
+        $this->assertNotEquals( false, $cache->restore( 0, $data['attributes'] 
) );
 
         $this->removeTempDir();
     }

Modified: trunk/Cache/tests/storage_test.php
==============================================================================
--- trunk/Cache/tests/storage_test.php [iso-8859-1] (original)
+++ trunk/Cache/tests/storage_test.php [iso-8859-1] Fri Oct  5 16:31:31 2007
@@ -92,10 +92,8 @@
      */
     public function testStoreSuccessWithoutAttributes()
     {
-//echo __FUNCTION__;
-        foreach ( $this->data as $id => $dataArr ) 
-        {
-//var_dump( $id );
+        foreach ( $this->data as $id => $dataArr ) 
+        {
             $this->storage->store( $id, $dataArr );
             $this->assertEquals( $this->storage->countDataItems( $id ), 1, 
'Storage file does not exist for ID: <' . $id . '>.' );
         }
@@ -108,7 +106,6 @@
      */
     public function testStoreSuccessWithAttributes()
     {
-//die();
         foreach ( $this->data as $id => $dataArr ) 
         {
             $attributes = array(
@@ -499,5 +496,85 @@
             );
         }
     }
+
+    public function testStoreRestoreNoAttributesSearch()
+    {
+        foreach ( $this->data as $id => $dataArr ) 
+        {
+            $this->storage->store( $id, $dataArr );
+            $data = $this->storage->restore( $id, array(), true );
+            $this->assertTrue( $data == $dataArr, "Restore data broken for ID 
<{$id}>." );
+        }
+    }
+
+    public function testStoreRestoreWithAttributesSearch()
+    {
+        foreach ( $this->data as $id => $dataArr ) 
+        {
+            $attributes = array(
+                'name'      => 'test',
+                'title'     => 'Test item',
+                'date'      => time().$id,
+            );
+            $this->storage->store( $id, $dataArr, $attributes );
+            $data = $this->storage->restore( $id, $attributes, true );
+            $this->assertTrue( $data == $dataArr, "Restore data broken for ID 
<{$id}>." );
+        }
+    }
+
+    public function testStoreRestoreWithAttributesSearchNoAttributes()
+    {
+        foreach ( $this->data as $id => $dataArr ) 
+        {
+            $attributes = array(
+                'name'      => 'test',
+                'title'     => 'Test item',
+                'date'      => time().$id,
+            );
+            $this->storage->store( $id, $dataArr, $attributes );
+            $data = $this->storage->restore( $id, array(), true );
+            $this->assertTrue( $data == $dataArr, "Restore data broken for ID 
<{$id}>." );
+        }
+    }
+
+    public function testStoreRestoreWithAttributesSearchNoId()
+    {
+        foreach ( $this->data as $id => $dataArr ) 
+        {
+            $attributes = array(
+                'name'      => 'test',
+                'title'     => 'Test item',
+                'date'      => time().$id,
+            );
+            $this->storage->store( $id, $dataArr, $attributes );
+            $data = $this->storage->restore( null, $attributes, true );
+            $this->assertTrue( $data == $dataArr, "Restore data broken for ID 
<{$id}>." );
+        }
+    }
+
+    public function testStoreRestoreWithAttributesSearchNoAttributesNoId()
+    {
+        $count = 0;
+        foreach ( $this->data as $id => $dataArr ) 
+        {
+            $attributes = array(
+                'name'      => 'test',
+                'title'     => 'Test item',
+                'date'      => time().$id,
+            );
+            $this->storage->store( $id, $dataArr, $attributes );
+            $data = $this->storage->restore( null, array(), true );
+            if ( $count === 0 )
+            {
+                $this->assertTrue( $data == $dataArr, "Restore data broken for 
ID <{$id}>." );
+            }
+            else
+            {
+                // There are more elements found during search, so false is 
returned
+                $this->assertTrue( $data == false, "Restore data broken for ID 
<{$id}>." );
+            }
+            $count++;
+        }
+    }
 }
 ?>


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to