diff --git a/Classes/PHPExcel/CachedObjectStorage/APC.php b/Classes/PHPExcel/CachedObjectStorage/APC.php index ea739eaa..8f1e931e 100644 --- a/Classes/PHPExcel/CachedObjectStorage/APC.php +++ b/Classes/PHPExcel/CachedObjectStorage/APC.php @@ -60,7 +60,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach * @return void * @throws PHPExcel_Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -162,6 +162,20 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + if ($this->_currentObjectID !== null) { + $this->_storeData(); + } + + return parent::getCellList(); + } + + /** * Delete a cell in cache identified by coordinate address * diff --git a/Classes/PHPExcel/CachedObjectStorage/CacheBase.php b/Classes/PHPExcel/CachedObjectStorage/CacheBase.php index 822a655a..fb34da02 100644 --- a/Classes/PHPExcel/CachedObjectStorage/CacheBase.php +++ b/Classes/PHPExcel/CachedObjectStorage/CacheBase.php @@ -232,6 +232,9 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase { * @return void */ public function copyCellCollection(PHPExcel_Worksheet $parent) { + $this->_currentCellIsDirty; + $this->_storeData(); + $this->_parent = $parent; if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) { $this->_currentObject->attach($parent); diff --git a/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php b/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php index 59f993ac..41bb168e 100644 --- a/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php +++ b/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php @@ -64,7 +64,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -132,6 +132,20 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + if ($this->_currentObjectID !== null) { + $this->_storeData(); + } + + return parent::getCellList(); + } + + /** * Clone the cell collection * diff --git a/Classes/PHPExcel/CachedObjectStorage/Igbinary.php b/Classes/PHPExcel/CachedObjectStorage/Igbinary.php index 3728d678..19aa2673 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Igbinary.php +++ b/Classes/PHPExcel/CachedObjectStorage/Igbinary.php @@ -42,7 +42,7 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -104,6 +104,20 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + if ($this->_currentObjectID !== null) { + $this->_storeData(); + } + + return parent::getCellList(); + } + + /** * Clear the cell collection and disconnect from our parent * diff --git a/Classes/PHPExcel/CachedObjectStorage/Memcache.php b/Classes/PHPExcel/CachedObjectStorage/Memcache.php index a72fa191..2f995a14 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Memcache.php +++ b/Classes/PHPExcel/CachedObjectStorage/Memcache.php @@ -64,7 +64,7 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -166,6 +166,20 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + if ($this->_currentObjectID !== null) { + $this->_storeData(); + } + + return parent::getCellList(); + } + + /** * Delete a cell in cache identified by coordinate address * diff --git a/Classes/PHPExcel/CachedObjectStorage/Memory.php b/Classes/PHPExcel/CachedObjectStorage/Memory.php index be84c43d..c3efa13b 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Memory.php +++ b/Classes/PHPExcel/CachedObjectStorage/Memory.php @@ -35,6 +35,14 @@ */ class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { + /** + * Dummy method callable from CacheBase, but unused by Memory cache + * + * @return void + */ + protected function _storeData() { + } // function _storeData() + /** * Add or Update a cell in cache identified by coordinate address * diff --git a/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php b/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php index 9ee3aaea..cc602795 100644 --- a/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php +++ b/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php @@ -42,7 +42,7 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -104,6 +104,20 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + if ($this->_currentObjectID !== null) { + $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 82dc167b..fbf22577 100644 --- a/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php +++ b/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php @@ -42,7 +42,7 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -104,6 +104,20 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + if ($this->_currentObjectID !== null) { + $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 e5af520b..cc046343 100644 --- a/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php +++ b/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php @@ -56,7 +56,7 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_ * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -124,6 +124,20 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_ } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + if ($this->_currentObjectID !== null) { + $this->_storeData(); + } + + return parent::getCellList(); + } + + /** * Clone the cell collection * diff --git a/Classes/PHPExcel/CachedObjectStorage/SQLite.php b/Classes/PHPExcel/CachedObjectStorage/SQLite.php index 56cc3f9b..05be66e0 100644 --- a/Classes/PHPExcel/CachedObjectStorage/SQLite.php +++ b/Classes/PHPExcel/CachedObjectStorage/SQLite.php @@ -56,7 +56,7 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -175,6 +175,10 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C * @return array of string */ public function getCellList() { + if ($this->_currentObjectID !== null) { + $this->_storeData(); + } + $query = "SELECT id FROM kvp_".$this->_TableName; $cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC); if ($cellIdsResult === false) @@ -196,6 +200,9 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C * @return void */ public function copyCellCollection(PHPExcel_Worksheet $parent) { + $this->_currentCellIsDirty; + $this->_storeData(); + // Get a new id for the new table name $tableName = str_replace('.','_',$this->_getUniqueID()); if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) diff --git a/Classes/PHPExcel/CachedObjectStorage/SQLite3.php b/Classes/PHPExcel/CachedObjectStorage/SQLite3.php index 3c3cf745..45204c24 100644 --- a/Classes/PHPExcel/CachedObjectStorage/SQLite3.php +++ b/Classes/PHPExcel/CachedObjectStorage/SQLite3.php @@ -56,7 +56,7 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_ * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -179,6 +179,10 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_ * @return array of string */ public function getCellList() { + if ($this->_currentObjectID !== null) { + $this->_storeData(); + } + $query = "SELECT id FROM kvp_".$this->_TableName; $cellIdsResult = $this->_DBHandle->query($query); if ($cellIdsResult === false) @@ -200,6 +204,9 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_ * @return void */ public function copyCellCollection(PHPExcel_Worksheet $parent) { + $this->_currentCellIsDirty; + $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) diff --git a/Classes/PHPExcel/CachedObjectStorage/Wincache.php b/Classes/PHPExcel/CachedObjectStorage/Wincache.php index 30fe7e1f..6065e17a 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Wincache.php +++ b/Classes/PHPExcel/CachedObjectStorage/Wincache.php @@ -57,7 +57,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage * @return void * @throws Exception */ - private function _storeData() { + protected function _storeData() { if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); @@ -166,6 +166,20 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage } // function getCacheData() + /** + * Get a list of all cell addresses currently held in cache + * + * @return array of string + */ + public function getCellList() { + if ($this->_currentObjectID !== null) { + $this->_storeData(); + } + + return parent::getCellList(); + } + + /** * Delete a cell in cache identified by coordinate address * diff --git a/Classes/PHPExcel/CachedObjectStorageFactory.php b/Classes/PHPExcel/CachedObjectStorageFactory.php index 90f0af0c..f68431e3 100644 --- a/Classes/PHPExcel/CachedObjectStorageFactory.php +++ b/Classes/PHPExcel/CachedObjectStorageFactory.php @@ -236,4 +236,12 @@ class PHPExcel_CachedObjectStorageFactory return FALSE; } // function getInstance() + + public static function finalize() + { + self::$_cacheStorageMethod = NULL; + self::$_cacheStorageClass = NULL; + self::$_storageMethodParameters = array(); + } + } diff --git a/changelog.txt b/changelog.txt index 3f0f81c9..5ab739cb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -42,6 +42,7 @@ Fixed in develop branch: - Bugfix: (alexgann) Work item GH-63 - Fix to cellExists for non-existent namedRanges - Bugfix: (MBaker) Work item 18844 - cache_in_memory_gzip "eats" last worksheet line, cache_in_memory doesn't - Bugfix: (Progi1984) Work item GH-22 - Sheet View in Excel5 Writer +- Bugfix: (amironov) Work item GH-82 - PHPExcel_Worksheet::getCellCollection() may not return last cached cell -------------------------------------------------------------------------------- diff --git a/unitTests/Classes/PHPExcel/Worksheet/CellCollectionTest.php b/unitTests/Classes/PHPExcel/Worksheet/CellCollectionTest.php new file mode 100644 index 00000000..c2c130d7 --- /dev/null +++ b/unitTests/Classes/PHPExcel/Worksheet/CellCollectionTest.php @@ -0,0 +1,31 @@ +getActiveSheet(); + $worksheet->setCellValue('A1', 1); + $worksheet->setCellValue('A2', 2); + $this->assertEquals($cells, $worksheet->getCellCollection(), "Cache method \"$method\"."); + PHPExcel_CachedObjectStorageFactory::finalize(); + } + } + +}