From befab29d70b47583ca9f7196c0442bba1a18450c Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Tue, 30 Oct 2012 13:03:40 +0600 Subject: [PATCH 1/3] PHPExcel_Worksheet::getCellCollection() unit test --- .../PHPExcel/CachedObjectStorageFactory.php | 8 ++++- .../PHPExcel/Worksheet/CellCollectionTest.php | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 unitTests/Classes/PHPExcel/Worksheet/CellCollectionTest.php diff --git a/Classes/PHPExcel/CachedObjectStorageFactory.php b/Classes/PHPExcel/CachedObjectStorageFactory.php index 45bae0d3d..cdfa2ef59 100644 --- a/Classes/PHPExcel/CachedObjectStorageFactory.php +++ b/Classes/PHPExcel/CachedObjectStorageFactory.php @@ -210,6 +210,12 @@ public static function initialize($method = self::cache_in_memory, $arguments = return TRUE; } // function initialize() + public static function finalize() + { + self::$_cacheStorageMethod = NULL; + self::$_cacheStorageClass = NULL; + self::$_storageMethodParameters = array(); + } /** * Initialise the cache storage @@ -236,4 +242,4 @@ public static function getInstance(PHPExcel_Worksheet $parent) return FALSE; } // function getInstance() -} \ No newline at end of file +} diff --git a/unitTests/Classes/PHPExcel/Worksheet/CellCollectionTest.php b/unitTests/Classes/PHPExcel/Worksheet/CellCollectionTest.php new file mode 100644 index 000000000..708f2b4dc --- /dev/null +++ b/unitTests/Classes/PHPExcel/Worksheet/CellCollectionTest.php @@ -0,0 +1,35 @@ +getActiveSheet(); + $worksheet->setCellValue('A1', 1); + $worksheet->setCellValue('A2', 2); + + $this->assertEquals($cells, $worksheet->getCellCollection(), "Cache method \"$method\"."); + + PHPExcel_CachedObjectStorageFactory::finalize(); + } + } + +} From 524900ea9c521ee9b196acd6c25e8c26586e9e8d Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Tue, 30 Oct 2012 13:48:15 +0600 Subject: [PATCH 2/3] PHPExcel_Worksheet::getCellCollection() may not return last cached cell --- Classes/PHPExcel/CachedObjectStorage/DiscISAM.php | 4 ++++ Classes/PHPExcel/CachedObjectStorage/Igbinary.php | 4 ++++ Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php | 4 ++++ Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php | 4 ++++ Classes/PHPExcel/CachedObjectStorage/PHPTemp.php | 4 ++++ Classes/PHPExcel/CachedObjectStorage/SQLite3.php | 1 + 6 files changed, 21 insertions(+) diff --git a/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php b/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php index 59f993ac3..4f94fb19c 100644 --- a/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php +++ b/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php @@ -97,6 +97,10 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; + if (!isset($this->_cellCache[$pCoord])) { + $this->_cellCache[$pCoord] = null; + } + return $cell; } // function addCacheData() diff --git a/Classes/PHPExcel/CachedObjectStorage/Igbinary.php b/Classes/PHPExcel/CachedObjectStorage/Igbinary.php index 3728d6784..dc030acc2 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Igbinary.php +++ b/Classes/PHPExcel/CachedObjectStorage/Igbinary.php @@ -70,6 +70,10 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; + if (!isset($this->_cellCache[$pCoord])) { + $this->_cellCache[$pCoord] = null; + } + return $cell; } // function addCacheData() diff --git a/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php b/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php index 9ee3aaea5..4661f39f8 100644 --- a/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php +++ b/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php @@ -70,6 +70,10 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; + if (!isset($this->_cellCache[$pCoord])) { + $this->_cellCache[$pCoord] = null; + } + return $cell; } // function addCacheData() diff --git a/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php b/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php index 82dc167b2..4a68a1471 100644 --- a/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php +++ b/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php @@ -70,6 +70,10 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; + if (!isset($this->_cellCache[$pCoord])) { + $this->_cellCache[$pCoord] = null; + } + return $cell; } // function addCacheData() diff --git a/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php b/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php index e5af520bf..34bed94b0 100644 --- a/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php +++ b/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php @@ -89,6 +89,10 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; + if (!isset($this->_cellCache[$pCoord])) { + $this->_cellCache[$pCoord] = null; + } + return $cell; } // function addCacheData() diff --git a/Classes/PHPExcel/CachedObjectStorage/SQLite3.php b/Classes/PHPExcel/CachedObjectStorage/SQLite3.php index 3c3cf745b..0f8445661 100644 --- a/Classes/PHPExcel/CachedObjectStorage/SQLite3.php +++ b/Classes/PHPExcel/CachedObjectStorage/SQLite3.php @@ -179,6 +179,7 @@ public function deleteCacheData($pCoord) { * @return array of string */ public function getCellList() { + $this->_storeData(); $query = "SELECT id FROM kvp_".$this->_TableName; $cellIdsResult = $this->_DBHandle->query($query); if ($cellIdsResult === false) From 9f4c88209e0670cda2fb889ea48863a5c31a5be5 Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Tue, 30 Oct 2012 13:48:57 +0600 Subject: [PATCH 3/3] PHPExcel_Worksheet::getCellCollection() may not return last cached cell --- .../PHPExcel/CachedObjectStorage/DiscISAM.php | 16 ++++++++++++---- .../PHPExcel/CachedObjectStorage/Igbinary.php | 15 +++++++++++---- .../PHPExcel/CachedObjectStorage/MemoryGZip.php | 15 +++++++++++---- .../CachedObjectStorage/MemorySerialized.php | 15 +++++++++++---- Classes/PHPExcel/CachedObjectStorage/PHPTemp.php | 16 ++++++++++++---- Classes/PHPExcel/CachedObjectStorage/SQLite3.php | 1 + 6 files changed, 58 insertions(+), 20 deletions(-) diff --git a/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php b/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php index 4f94fb19c..2abf7d555 100644 --- a/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php +++ b/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php @@ -97,10 +97,6 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; - if (!isset($this->_cellCache[$pCoord])) { - $this->_cellCache[$pCoord] = null; - } - return $cell; } // function addCacheData() @@ -136,6 +132,17 @@ public function getCacheData($pCoord) { } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + $this->_storeData(); + return parent::getCellList(); + } + + /** * Clone the cell collection * @@ -143,6 +150,7 @@ public function getCacheData($pCoord) { * @return void */ public function copyCellCollection(PHPExcel_Worksheet $parent) { + $this->_storeData(); parent::copyCellCollection($parent); // Get a new id for the new file name $baseUnique = $this->_getUniqueID(); diff --git a/Classes/PHPExcel/CachedObjectStorage/Igbinary.php b/Classes/PHPExcel/CachedObjectStorage/Igbinary.php index dc030acc2..a8bccb2a9 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Igbinary.php +++ b/Classes/PHPExcel/CachedObjectStorage/Igbinary.php @@ -70,10 +70,6 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; - if (!isset($this->_cellCache[$pCoord])) { - $this->_cellCache[$pCoord] = null; - } - return $cell; } // function addCacheData() @@ -108,6 +104,17 @@ public function getCacheData($pCoord) { } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + $this->_storeData(); + return parent::getCellList(); + } + + /** * Clear the cell collection and disconnect from our parent * diff --git a/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php b/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php index 4661f39f8..518c737fe 100644 --- a/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php +++ b/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php @@ -70,10 +70,6 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; - if (!isset($this->_cellCache[$pCoord])) { - $this->_cellCache[$pCoord] = null; - } - return $cell; } // function addCacheData() @@ -108,6 +104,17 @@ public function getCacheData($pCoord) { } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + $this->_storeData(); + return parent::getCellList(); + } + + /** * Clear the cell collection and disconnect from our parent * diff --git a/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php b/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php index 4a68a1471..21144c5f4 100644 --- a/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php +++ b/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php @@ -70,10 +70,6 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; - if (!isset($this->_cellCache[$pCoord])) { - $this->_cellCache[$pCoord] = null; - } - return $cell; } // function addCacheData() @@ -108,6 +104,17 @@ public function getCacheData($pCoord) { } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + $this->_storeData(); + return parent::getCellList(); + } + + /** * Clear the cell collection and disconnect from our parent * diff --git a/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php b/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php index 34bed94b0..86444b54a 100644 --- a/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php +++ b/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php @@ -89,10 +89,6 @@ public function addCacheData($pCoord, PHPExcel_Cell $cell) { $this->_currentObject = $cell; $this->_currentCellIsDirty = true; - if (!isset($this->_cellCache[$pCoord])) { - $this->_cellCache[$pCoord] = null; - } - return $cell; } // function addCacheData() @@ -128,6 +124,17 @@ public function getCacheData($pCoord) { } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + $this->_storeData(); + return parent::getCellList(); + } + + /** * Clone the cell collection * @@ -135,6 +142,7 @@ public function getCacheData($pCoord) { * @return void */ public function copyCellCollection(PHPExcel_Worksheet $parent) { + $this->_storeData(); parent::copyCellCollection($parent); // Open a new stream for the cell cache data $newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+'); diff --git a/Classes/PHPExcel/CachedObjectStorage/SQLite3.php b/Classes/PHPExcel/CachedObjectStorage/SQLite3.php index 0f8445661..4ce217d89 100644 --- a/Classes/PHPExcel/CachedObjectStorage/SQLite3.php +++ b/Classes/PHPExcel/CachedObjectStorage/SQLite3.php @@ -201,6 +201,7 @@ public function getCellList() { * @return void */ public function copyCellCollection(PHPExcel_Worksheet $parent) { + $this->_storeData(); // Get a new id for the new table name $tableName = str_replace('.','_',$this->_getUniqueID()); if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)