Commit cf00677d authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-230 Replaced RuntimeException with UnavailableException (newly

introduced), changed IStateMachine so GetState() and SetState() can
throw this exception, adjusted interface documentation in
filestatemachine.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 232456ab
......@@ -230,7 +230,7 @@ class SqlStateMachine implements IStateMachine {
*
* @access public
* @return boolean
* @throws StateInvalidException
* @throws StateInvalidException, UnavailableException
*/
public function SetState($state, $devid, $type, $key = null, $counter = false) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->SetState(): devid:'%s' type:'%s' key:'%s' counter:'%s'", $devid, $type, ($key == null ? 'null' : $key), Utils::PrintAsString($counter)));
......@@ -271,7 +271,7 @@ class SqlStateMachine implements IStateMachine {
if (!$sth->execute() ) {
$errInfo = $sth->errorInfo();
$this->clearConnection($this->dbh, $sth);
throw new FatalException(sprintf("SqlStateMachine->SetState(): Could not write state: %s", isset($errInfo[2]) ? $errInfo[2] : 'unknown'));
throw new UnavailableException(sprintf("SqlStateMachine->SetState(): Could not write state: %s", isset($errInfo[2]) ? $errInfo[2] : 'unknown'));
}
else {
$bytes = strlen(serialize($state));
......@@ -279,7 +279,7 @@ class SqlStateMachine implements IStateMachine {
}
catch(PDOException $ex) {
$this->clearConnection($this->dbh, $sth);
throw new FatalException(sprintf("SqlStateMachine->SetState(): Could not write state: %s", $ex->getMessage()));
throw new UnavailableException(sprintf("SqlStateMachine->SetState(): Could not write state: %s", $ex->getMessage()));
}
return $bytes;
......@@ -297,7 +297,6 @@ class SqlStateMachine implements IStateMachine {
*
* @access public
* @return
* @throws StateInvalidException
*/
public function CleanStates($devid, $type, $key = null, $counter = false) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->CleanStates(): devid:'%s' type:'%s' key:'%s' counter:'%s'", $devid, $type, ($key == null ? 'null' : $key), Utils::PrintAsString($counter)));
......@@ -676,12 +675,12 @@ class SqlStateMachine implements IStateMachine {
*
* @access private
* @return boolean
* @throws RuntimeException
* @throws UnavailableException
*/
private function checkDbAndTables() {
ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->checkDbAndTables(): Checking if database and tables are available.");
try {
$sqlStmt = sprintf("SHOW TABLES FROM %s LIKE 'zpush%%'", STATE_SQL_DATABASE);
$sqlStmt = sprintf("SHOW TABLES FROM %s", STATE_SQL_DATABASE);
$sth = $this->getDbh(false)->prepare($sqlStmt);
$sth->execute();
if ($sth->rowCount() != 3) {
......@@ -697,7 +696,7 @@ class SqlStateMachine implements IStateMachine {
$this->createDB();
}
else {
throw new RuntimeException(sprintf("SqlStateMachine->checkDbAndTables(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
throw new UnavailableException(sprintf("SqlStateMachine->checkDbAndTables(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
}
}
......@@ -710,7 +709,7 @@ class SqlStateMachine implements IStateMachine {
*
* @access private
* @return boolean
* @throws RuntimeException
* @throws UnavailableException
*/
private function createDB() {
ZLog::Write(LOGLEVEL_INFO, sprintf("SqlStateMachine->createDB(): database '%s' is not available, trying to create it.", STATE_SQL_DATABASE));
......@@ -726,7 +725,7 @@ class SqlStateMachine implements IStateMachine {
return true;
}
catch (PDOException $ex) {
throw new RuntimeException(sprintf("SqlStateMachine->createDB(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
throw new UnavailableException(sprintf("SqlStateMachine->createDB(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
}
}
......@@ -735,7 +734,7 @@ class SqlStateMachine implements IStateMachine {
*
* @access private
* @return boolean
* @throws RuntimeException
* @throws UnavailableException
*/
private function createTables() {
ZLog::Write(LOGLEVEL_INFO, "SqlStateMachine->createTables(): tables are not available, trying to create them.");
......@@ -747,7 +746,7 @@ class SqlStateMachine implements IStateMachine {
return true;
}
catch (PDOException $ex) {
throw new RuntimeException(sprintf("SqlStateMachine->createTables(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
throw new UnavailableException(sprintf("SqlStateMachine->createTables(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
}
}
......@@ -756,7 +755,7 @@ class SqlStateMachine implements IStateMachine {
*
* @access public
* @return boolean
* @throws RuntimeException
* @throws UnavailableException
*/
public function DoTablesHaveData() {
try {
......@@ -796,7 +795,7 @@ class SqlStateMachine implements IStateMachine {
return ($dataSettings || $dataStates || $dataUsers);
}
catch (PDOException $ex) {
throw new RuntimeException(sprintf("SqlStateMachine->DoTablesHaveData(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
throw new UnavailableException(sprintf("SqlStateMachine->DoTablesHaveData(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
}
return false;
}
......
......@@ -117,7 +117,7 @@ class FileStateMachine implements IStateMachine {
*
* @access public
* @return mixed
* @throws StateNotFoundException, StateInvalidException
* @throws StateNotFoundException, StateInvalidException, UnavailableException
*/
public function GetState($devid, $type, $key = false, $counter = false, $cleanstates = true) {
if ($counter && $cleanstates)
......@@ -148,7 +148,7 @@ class FileStateMachine implements IStateMachine {
*
* @access public
* @return boolean
* @throws StateInvalidException
* @throws StateInvalidException, UnavailableException
*/
public function SetState($state, $devid, $type, $key = false, $counter = false) {
$state = serialize($state);
......
<?php
/***********************************************
* File : unavailableexception.php
* Project : Z-Push
* Descr : This is a fatal exception when e.g. a subsystem is not
* available. The mobile should retry later.
*
* Created : 11.05.2016
*
* Copyright 2016 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation with the following additional
* term according to sec. 7:
*
* According to sec. 7 of the GNU Affero General Public License, version 3,
* the terms of the AGPL are supplemented with the following terms:
*
* "Zarafa" is a registered trademark of Zarafa B.V.
* "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
* The licensing of the Program under the AGPL does not imply a trademark license.
* Therefore any rights, title and interest in our trademarks remain entirely with us.
*
* However, if you propagate an unmodified version of the Program you are
* allowed to use the term "Z-Push" to indicate that you distribute the Program.
* Furthermore you may use our trademarks where it is necessary to indicate
* the intended purpose of a product or service provided you use it in accordance
* with honest practices in industrial or commercial matters.
* If you want to propagate modified versions of the Program under the name "Z-Push",
* you may only do so if you have a written permission by Zarafa Deutschland GmbH
* (to acquire a permission please contact Zarafa at trademark@zarafa.com).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/
class UnavailableException extends FatalException {}
\ No newline at end of file
......@@ -99,7 +99,7 @@ interface IStateMachine {
*
* @access public
* @return mixed
* @throws StateNotFoundException, StateInvalidException
* @throws StateNotFoundException, StateInvalidException, UnavailableException
*/
public function GetState($devid, $type, $key = false, $counter = false, $cleanstates = true);
......@@ -114,7 +114,7 @@ interface IStateMachine {
*
* @access public
* @return boolean
* @throws StateInvalidException
* @throws StateInvalidException, UnavailableException
*/
public function SetState($state, $devid, $type, $key = false, $counter = false);
......
......@@ -147,6 +147,7 @@ return array(
'TaskRequest' => $baseDir . '/backend/zarafa/mapi/class.taskrequest.php',
'TimezoneUtil' => $baseDir . '/lib/utils/timezoneutil.php',
'TopCollector' => $baseDir . '/lib/core/topcollector.php',
'UnavailableException' => $baseDir . '/lib/exceptions/unavailableexception.php',
'Utils' => $baseDir . '/lib/utils/utils.php',
'ValidateCert' => $baseDir . '/lib/request/validatecert.php',
'WBXMLDecoder' => $baseDir . '/lib/wbxml/wbxmldecoder.php',
......
......@@ -154,6 +154,7 @@ class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f
'TaskRequest' => __DIR__ . '/../..' . '/backend/zarafa/mapi/class.taskrequest.php',
'TimezoneUtil' => __DIR__ . '/../..' . '/lib/utils/timezoneutil.php',
'TopCollector' => __DIR__ . '/../..' . '/lib/core/topcollector.php',
'UnavailableException' => __DIR__ . '/../..' . '/lib/exceptions/unavailableexception.php',
'Utils' => __DIR__ . '/../..' . '/lib/utils/utils.php',
'ValidateCert' => __DIR__ . '/../..' . '/lib/request/validatecert.php',
'WBXMLDecoder' => __DIR__ . '/../..' . '/lib/wbxml/wbxmldecoder.php',
......
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