Bugfix: (manual merge from a pull request from amironov) Work item GH-82 - PHPExcel_Worksheet::getCellCollection() may not return last cached cell

This commit is contained in:
Mark Baker 2012-11-29 23:57:12 +00:00
parent a032194211
commit 487f4b79ec
15 changed files with 187 additions and 10 deletions

View File

@ -60,7 +60,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -162,6 +162,20 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
} // function getCacheData() } // 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 * Delete a cell in cache identified by coordinate address
* *

View File

@ -232,6 +232,9 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_Worksheet $parent) {
$this->_currentCellIsDirty;
$this->_storeData();
$this->_parent = $parent; $this->_parent = $parent;
if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) { if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) {
$this->_currentObject->attach($parent); $this->_currentObject->attach($parent);

View File

@ -64,7 +64,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -132,6 +132,20 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
} // function getCacheData() } // 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 * Clone the cell collection
* *

View File

@ -42,7 +42,7 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -104,6 +104,20 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage
} // function getCacheData() } // 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 * Clear the cell collection and disconnect from our parent
* *

View File

@ -64,7 +64,7 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -166,6 +166,20 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
} // function getCacheData() } // 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 * Delete a cell in cache identified by coordinate address
* *

View File

@ -35,6 +35,14 @@
*/ */
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { 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 * Add or Update a cell in cache identified by coordinate address
* *

View File

@ -42,7 +42,7 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -104,6 +104,20 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
} // function getCacheData() } // 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 * Clear the cell collection and disconnect from our parent
* *

View File

@ -42,7 +42,7 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -104,6 +104,20 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
} // function getCacheData() } // 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 * Clear the cell collection and disconnect from our parent
* *

View File

@ -56,7 +56,7 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -124,6 +124,20 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
} // function getCacheData() } // 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 * Clone the cell collection
* *

View File

@ -56,7 +56,7 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -175,6 +175,10 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList() {
if ($this->_currentObjectID !== null) {
$this->_storeData();
}
$query = "SELECT id FROM kvp_".$this->_TableName; $query = "SELECT id FROM kvp_".$this->_TableName;
$cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC); $cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC);
if ($cellIdsResult === false) if ($cellIdsResult === false)
@ -196,6 +200,9 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_Worksheet $parent) {
$this->_currentCellIsDirty;
$this->_storeData();
// Get a new id for the new table name // Get a new id for the new table name
$tableName = str_replace('.','_',$this->_getUniqueID()); $tableName = str_replace('.','_',$this->_getUniqueID());
if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)

View File

@ -56,7 +56,7 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -179,6 +179,10 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList() {
if ($this->_currentObjectID !== null) {
$this->_storeData();
}
$query = "SELECT id FROM kvp_".$this->_TableName; $query = "SELECT id FROM kvp_".$this->_TableName;
$cellIdsResult = $this->_DBHandle->query($query); $cellIdsResult = $this->_DBHandle->query($query);
if ($cellIdsResult === false) if ($cellIdsResult === false)
@ -200,6 +204,9 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_Worksheet $parent) {
$this->_currentCellIsDirty;
$this->_storeData();
// Get a new id for the new table name // Get a new id for the new table name
$tableName = str_replace('.','_',$this->_getUniqueID()); $tableName = str_replace('.','_',$this->_getUniqueID());
if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)

View File

@ -57,7 +57,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function _storeData() { protected function _storeData() {
if ($this->_currentCellIsDirty) { if ($this->_currentCellIsDirty) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -166,6 +166,20 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
} // function getCacheData() } // 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 * Delete a cell in cache identified by coordinate address
* *

View File

@ -236,4 +236,12 @@ class PHPExcel_CachedObjectStorageFactory
return FALSE; return FALSE;
} // function getInstance() } // function getInstance()
public static function finalize()
{
self::$_cacheStorageMethod = NULL;
self::$_cacheStorageClass = NULL;
self::$_storageMethodParameters = array();
}
} }

View File

@ -42,6 +42,7 @@ Fixed in develop branch:
- Bugfix: (alexgann) Work item GH-63 - Fix to cellExists for non-existent namedRanges - 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: (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: (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
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -0,0 +1,31 @@
<?php
class CellCollectionTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!defined('PHPEXCEL_ROOT'))
{
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
public function testCacheLastCell()
{
$methods = PHPExcel_CachedObjectStorageFactory::getCacheStorageMethods();
foreach ($methods as $method) {
PHPExcel_CachedObjectStorageFactory::initialize($method);
$workbook = new PHPExcel();
$cells = array('A1', 'A2');
$worksheet = $workbook->getActiveSheet();
$worksheet->setCellValue('A1', 1);
$worksheet->setCellValue('A2', 2);
$this->assertEquals($cells, $worksheet->getCellCollection(), "Cache method \"$method\".");
PHPExcel_CachedObjectStorageFactory::finalize();
}
}
}