Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

PHPExcel_Worksheet::getCellCollection() may not return last cached cell #82

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Classes/PHPExcel/CachedObjectStorage/DiscISAM.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,25 @@ 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
*
* @param PHPExcel_Worksheet $parent The new worksheet
* @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();
Expand Down
11 changes: 11 additions & 0 deletions Classes/PHPExcel/CachedObjectStorage/Igbinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,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
*
Expand Down
11 changes: 11 additions & 0 deletions Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,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
*
Expand Down
11 changes: 11 additions & 0 deletions Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,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
*
Expand Down
12 changes: 12 additions & 0 deletions Classes/PHPExcel/CachedObjectStorage/PHPTemp.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,25 @@ 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
*
* @param PHPExcel_Worksheet $parent The new worksheet
* @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+');
Expand Down
2 changes: 2 additions & 0 deletions Classes/PHPExcel/CachedObjectStorage/SQLite3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -200,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)
Expand Down
8 changes: 7 additions & 1 deletion Classes/PHPExcel/CachedObjectStorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -236,4 +242,4 @@ public static function getInstance(PHPExcel_Worksheet $parent)
return FALSE;
} // function getInstance()

}
}
35 changes: 35 additions & 0 deletions unitTests/Classes/PHPExcel/Worksheet/CellCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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();
}
}

}