Commit ba8eb4ec authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #386 in ZP/z-push from...

Merge pull request #386 in ZP/z-push from bugfix/ZP-1054-ping-triggers-hierarchy-sync-if-database to develop

* commit '5f4d1916':
  ZP-1054 Use sprintf.
  ZP-1054 Throw UnavailableException if the hash cannot be loaded.
parents 09d36fca 5f4d1916
......@@ -143,7 +143,7 @@ class SqlStateMachine implements IStateMachine {
*
* @access public
* @return string
* @throws StateNotFoundException, StateInvalidException
* @throws StateNotFoundException, StateInvalidException, UnavailableException
*/
public function GetStateHash($devid, $type, $key = null, $counter = false) {
$hash = null;
......@@ -155,8 +155,12 @@ class SqlStateMachine implements IStateMachine {
$record = $sth->fetch(PDO::FETCH_ASSOC);
if (!$record) {
$errCode = $sth->errorCode();
$this->clearConnection($this->dbh, $sth, $record);
throw new StateNotFoundException("SqlStateMachine->GetStateHash(): Could not locate state");
if ($errCode == 'HY000') {
throw new UnavailableException("SqlStateMachine->GetStateHash(): Database not available", $errCode, null, LOGLEVEL_WARN);
}
throw new StateNotFoundException(sprintf("SqlStateMachine->GetStateHash(): Could not locate state with error code: %s", $errCode));
}
else {
// datetime->format("U") returns EPOCH
......
......@@ -1001,6 +1001,13 @@ class DeviceManager {
catch (StateNotFoundException $snfex) {
$this->hierarchySyncRequired = true;
}
catch (UnavailableException $uaex) {
// This is temporary and can be ignored e.g. in PING - see https://jira.z-hub.io/browse/ZP-1054
// If the hash was not available before we treat it like a StateNotFoundException.
if ($this->deviceHash === false) {
$this->hierarchySyncRequired = true;
}
}
return true;
}
......
......@@ -92,7 +92,7 @@ class FileStateMachine implements IStateMachine {
*
* @access public
* @return string
* @throws StateNotFoundException, StateInvalidException
* @throws StateNotFoundException, StateInvalidException, UnavailableException
*/
public function GetStateHash($devid, $type, $key = false, $counter = false) {
$filename = $this->getFullFilePath($devid, $type, $key, $counter);
......
......@@ -82,7 +82,7 @@ interface IStateMachine {
*
* @access public
* @return string
* @throws StateNotFoundException, StateInvalidException
* @throws StateNotFoundException, StateInvalidException, UnavailableException
*/
public function GetStateHash($devid, $type, $key = false, $counter = false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment