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

Fix for an error if save handler use mysql and destroy expired session. #109

Merged
merged 9 commits into from
Aug 11, 2019
1 change: 1 addition & 0 deletions src/SaveHandler/DbTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function read($id, $destroyExpired = true)
return (string) $row->{$this->options->getDataColumn()};
}
if ($destroyExpired) {
$rows = null;
$this->destroy($id);
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/SaveHandler/DbTableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,33 @@ public function testExpiredSessionDoesNotCauseARecursion()
$this->adapter->query("DELETE FROM `sessions` WHERE `{$this->options->getIdColumn()}` = '123';");
}

public function testReadDestroysExpiredSession()
{
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
$saveHandler->open('savepath', 'sessionname');

$id = '345';

$this->assertTrue($saveHandler->write($id, serialize($this->testArray)));

// set lifetime to 0
$query = <<<EOD
UPDATE `sessions`
SET `{$this->options->getLifetimeColumn()}` = 0
WHERE
`{$this->options->getIdColumn()}` = {$id}
AND `{$this->options->getNameColumn()}` = 'sessionname'
EOD;
$this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);

// check destroy session
$result = $saveHandler->read($id);
$this->assertEquals($result, '');

// cleans the test record from the db
$this->adapter->query("DELETE FROM `sessions` WHERE `{$this->options->getIdColumn()}` = {$id};");
}

/**
* Sets up the database connection and creates the table for session data
*
Expand Down