Commit ba9443d7 authored by Manfred Kutas's avatar Manfred Kutas

ZP-230 Capitalised SQL key words in statements.

Released under the Affero GNU General Public License (AGPL) version 3.
parent be7b3270
...@@ -73,7 +73,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -73,7 +73,7 @@ class SqlStateMachine implements IStateMachine {
ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine(): init"); ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine(): init");
if (!trim(STATE_SQL_SERVER) || !trim(STATE_SQL_PORT) || !trim(STATE_SQL_DATABASE) || !trim(STATE_SQL_USER)) { if (!trim(STATE_SQL_SERVER) || !trim(STATE_SQL_PORT) || !trim(STATE_SQL_DATABASE) || !trim(STATE_SQL_USER)) {
throw new FatalMisconfigurationException("Missing configuration for the state sql. Check STATE_SQL_* values in the config.php."); throw new FatalMisconfigurationException("SqlStateMachine(): missing configuration for the state sql. Check STATE_SQL_* values in the config.php.");
} }
$this->options = array(); $this->options = array();
...@@ -86,7 +86,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -86,7 +86,7 @@ class SqlStateMachine implements IStateMachine {
$this->checkDbAndTables(); $this->checkDbAndTables();
} }
catch(PDOException $ex) { catch(PDOException $ex) {
throw new FatalMisconfigurationException(sprintf("Not possible to connect to the state database: %s", $ex->getMessage())); throw new FatalMisconfigurationException(sprintf("SqlStateMachine(): not possible to connect to the state database: %s", $ex->getMessage()));
} }
$this->clearConnection($this->dbh); $this->clearConnection($this->dbh);
...@@ -108,9 +108,9 @@ class SqlStateMachine implements IStateMachine { ...@@ -108,9 +108,9 @@ class SqlStateMachine implements IStateMachine {
* @throws StateNotFoundException, StateInvalidException * @throws StateNotFoundException, StateInvalidException
*/ */
public function GetStateHash($devid, $type, $key = null, $counter = false) { public function GetStateHash($devid, $type, $key = null, $counter = false) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetStateHash(): '%s', '%s', '%s', '%s'", $devid, $type, $key, $counter)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetStateHash(): '%s', '%s', '%s', '%s'", $devid, $type, ($key == null ? 'null' : $key) , Utils::PrintAsString($counter)));
$sql = "select updated_at from zpush_states where device_id = :devid and state_type = :type and uuid ". (($key == null) ? " is " : " = ") . ":key and counter = :counter"; $sql = "SELECT updated_at FROM zpush_states WHERE device_id = :devid AND state_type = :type AND uuid ". (($key == null) ? " IS " : " = ") . ":key AND counter = :counter";
$params = $this->getParams($devid, $type, $key, $counter); $params = $this->getParams($devid, $type, $key, $counter);
$hash = null; $hash = null;
...@@ -126,7 +126,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -126,7 +126,7 @@ class SqlStateMachine implements IStateMachine {
$record = $sth->fetch(PDO::FETCH_ASSOC); $record = $sth->fetch(PDO::FETCH_ASSOC);
if (!$record) { if (!$record) {
$this->clearConnection($this->dbh, $sth, $record); $this->clearConnection($this->dbh, $sth, $record);
throw new StateNotFoundException(sprintf("SqlStateMachine->GetStateHash(): Could not locate state")); throw new StateNotFoundException("SqlStateMachine->GetStateHash(): Could not locate state");
} }
else { else {
// datetime->format("U") returns EPOCH // datetime->format("U") returns EPOCH
...@@ -148,7 +148,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -148,7 +148,7 @@ class SqlStateMachine implements IStateMachine {
/** /**
* Gets a state for a specified key and counter. * Gets a state for a specified key and counter.
* This method sould call IStateMachine->CleanStates() * This method should call IStateMachine->CleanStates()
* to remove older states (same key, previous counters). * to remove older states (same key, previous counters).
* *
* @param string $devid the device id * @param string $devid the device id
...@@ -162,11 +162,11 @@ class SqlStateMachine implements IStateMachine { ...@@ -162,11 +162,11 @@ class SqlStateMachine implements IStateMachine {
* @throws StateNotFoundException, StateInvalidException * @throws StateNotFoundException, StateInvalidException
*/ */
public function GetState($devid, $type, $key = null, $counter = false, $cleanstates = true) { public function GetState($devid, $type, $key = null, $counter = false, $cleanstates = true) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetState(): '%s', '%s', '%s', '%s', '%s'", $devid, $type, $key, $counter, $cleanstates)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetState(): '%s', '%s', '%s', '%s', '%s'", $devid, $type, ($key == null ? 'null' : $key), Utils::PrintAsString($counter), Utils::PrintAsString($cleanstates)));
if ($counter && $cleanstates) if ($counter && $cleanstates)
$this->CleanStates($devid, $type, $key, $counter); $this->CleanStates($devid, $type, $key, $counter);
$sql = "select state_data from zpush_states where device_id = :devid and state_type = :type and uuid ". (($key == null) ? " is " : " = ") . ":key and counter = :counter"; $sql = "SELECT state_data FROM zpush_states WHERE device_id = :devid AND state_type = :type AND uuid ". (($key == null) ? " IS " : " = ") . ":key AND counter = :counter";
$params = $this->getParams($devid, $type, $key, $counter); $params = $this->getParams($devid, $type, $key, $counter);
$data = null; $data = null;
...@@ -184,7 +184,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -184,7 +184,7 @@ class SqlStateMachine implements IStateMachine {
$this->clearConnection($this->dbh, $sth, $record); $this->clearConnection($this->dbh, $sth, $record);
// throw an exception on all other states, but not FAILSAVE as it's most of the times not there by default // throw an exception on all other states, but not FAILSAVE as it's most of the times not there by default
if ($type !== IStateMachine::FAILSAVE) { if ($type !== IStateMachine::FAILSAVE) {
throw new StateNotFoundException(sprintf("SqlStateMachine->GetState(): Could not locate state")); throw new StateNotFoundException("SqlStateMachine->GetState(): Could not locate state");
} }
} }
else { else {
...@@ -221,9 +221,9 @@ class SqlStateMachine implements IStateMachine { ...@@ -221,9 +221,9 @@ class SqlStateMachine implements IStateMachine {
* @throws StateInvalidException * @throws StateInvalidException
*/ */
public function SetState($state, $devid, $type, $key = null, $counter = false) { public function SetState($state, $devid, $type, $key = null, $counter = false) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->SetState(): '%s', '%s', '%s', '%s'", $devid, $type, $key, $counter)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->SetState(): '%s', '%s', '%s', '%s'", $devid, $type, ($key == null ? 'null' : $key), Utils::PrintAsString($counter)));
$sql = "select device_id from zpush_states where device_id = :devid and state_type = :type and uuid ". (($key == null) ? " is " : " = ") . ":key and counter = :counter"; $sql = "SELECT device_id FROM zpush_states WHERE device_id = :devid AND state_type = :type AND uuid ". (($key == null) ? " IS " : " = ") . ":key AND counter = :counter";
$params = $this->getParams($devid, $type, $key, $counter); $params = $this->getParams($devid, $type, $key, $counter);
$sth = null; $sth = null;
...@@ -240,14 +240,14 @@ class SqlStateMachine implements IStateMachine { ...@@ -240,14 +240,14 @@ class SqlStateMachine implements IStateMachine {
$record = $sth->fetch(PDO::FETCH_ASSOC); $record = $sth->fetch(PDO::FETCH_ASSOC);
if (!$record) { if (!$record) {
// New record // New record
$sql = "insert into zpush_states (device_id, state_type, uuid, counter, state_data, created_at, updated_at) values (:devid, :type, :key, :counter, :data, :created_at, :updated_at)"; $sql = "INSERT INTO zpush_states (device_id, state_type, uuid, counter, state_data, created_at, updated_at) VALUES (:devid, :type, :key, :counter, :data, :created_at, :updated_at)";
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
$sth->bindValue(":created_at", $this->getNow(), PDO::PARAM_STR); $sth->bindValue(":created_at", $this->getNow(), PDO::PARAM_STR);
} }
else { else {
// Existing record, we update it // Existing record, we update it
$sql = "update zpush_states set state_data = :data, updated_at = :updated_at where device_id = :devid and state_type = :type and uuid " . (($key == null) ? " is " : " = ") .":key and counter = :counter"; $sql = "UPDATE zpush_states SET state_data = :data, updated_at = :updated_at WHERE device_id = :devid AND state_type = :type AND uuid " . (($key == null) ? " IS " : " = ") .":key AND counter = :counter";
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
} }
...@@ -261,7 +261,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -261,7 +261,7 @@ class SqlStateMachine implements IStateMachine {
if (!$sth->execute() ) { if (!$sth->execute() ) {
$this->clearConnection($this->dbh, $sth); $this->clearConnection($this->dbh, $sth);
throw new FatalMisconfigurationException(sprintf("SqlStateMachine->SetState(): Could not write state")); throw new FatalMisconfigurationException("SqlStateMachine->SetState(): Could not write state");
} }
else { else {
$bytes = strlen(serialize($state)); $bytes = strlen(serialize($state));
...@@ -291,16 +291,16 @@ class SqlStateMachine implements IStateMachine { ...@@ -291,16 +291,16 @@ class SqlStateMachine implements IStateMachine {
* @return * @return
* @throws StateInvalidException * @throws StateInvalidException
*/ */
public function CleanStates($devid, $type, $key, $counter = false) { public function CleanStates($devid, $type, $key = null, $counter = false) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->CleanStates(): '%s', '%s', '%s', '%s'", $devid, $type, $key, $counter)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->CleanStates(): '%s', '%s', '%s', '%s'", $devid, $type, ($key == null ? 'null' : $key), Utils::PrintAsString($counter)));
if ($counter === false) { if ($counter === false) {
// Remove all the states. Counter are -1 or > 0, then deleting >= -1 deletes all // Remove all the states. Counter are -1 or > 0, then deleting >= -1 deletes all
$sql = "delete from zpush_states where device_id = :devid and state_type = :type and uuid = :key and counter >= :counter"; $sql = "DELETE FROM zpush_states WHERE device_id = :devid AND state_type = :type AND uuid = :key AND counter >= :counter";
} }
else { else {
$sql = "delete from zpush_states where device_id = :devid and state_type = :type and uuid = :key and counter < :counter"; $sql = "DELETE FROM zpush_states WHERE device_id = :devid AND state_type = :type AND uuid = :key AND counter < :counter";
} }
$params = $this->getParams($devid, $type, $key, $counter); $params = $this->getParams($devid, $type, $key, $counter);
...@@ -338,7 +338,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -338,7 +338,7 @@ class SqlStateMachine implements IStateMachine {
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
$sql = "select username from zpush_users where username = :username and device_id = :devid"; $sql = "SELECT username FROM zpush_users WHERE username = :username AND device_id = :devid";
$params = array(":username" => $username, ":devid" => $devid); $params = array(":username" => $username, ":devid" => $devid);
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
...@@ -350,7 +350,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -350,7 +350,7 @@ class SqlStateMachine implements IStateMachine {
} }
else { else {
$sth = null; $sth = null;
$sql = "insert into zpush_users (username, device_id, created_at, updated_at) values (:username, :devid, :created_at, :updated_at)"; $sql = "INSERT INTO zpush_users (username, device_id, created_at, updated_at) VALUES (:username, :devid, :created_at, :updated_at)";
$params[":created_at"] = ($createdAt != null) ? $createdAt : $this->getNow(); $params[":created_at"] = ($createdAt != null) ? $createdAt : $this->getNow();
$params[":updated_at"] = ($updatedAt != null) ? $updatedAt : $this->getNow(); $params[":updated_at"] = ($updatedAt != null) ? $updatedAt : $this->getNow();
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
...@@ -359,7 +359,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -359,7 +359,7 @@ class SqlStateMachine implements IStateMachine {
$changed = true; $changed = true;
} }
else { else {
ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->LinkUserDevice(): Unable to link user-device")); ZLog::Write(LOGLEVEL_ERROR, "SqlStateMachine->LinkUserDevice(): Unable to link user-device");
} }
} }
} }
...@@ -390,7 +390,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -390,7 +390,7 @@ class SqlStateMachine implements IStateMachine {
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
$sql = "delete from zpush_users where username = :username and device_id = :devid"; $sql = "DELETE FROM zpush_users WHERE username = :username AND device_id = :devid";
$params = array(":username" => $username, ":devid" => $devid); $params = array(":username" => $username, ":devid" => $devid);
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
...@@ -427,7 +427,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -427,7 +427,7 @@ class SqlStateMachine implements IStateMachine {
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
$sql = "select device_id, username from zpush_users order by username"; $sql = "SELECT device_id, username FROM zpush_users ORDER BY username";
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
$sth->execute(); $sth->execute();
...@@ -467,11 +467,11 @@ class SqlStateMachine implements IStateMachine { ...@@ -467,11 +467,11 @@ class SqlStateMachine implements IStateMachine {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
if ($username === false) { if ($username === false) {
$sql = "select distinct(device_id) from zpush_users order by device_id"; $sql = "SELECT DISTINCT(device_id) FROM zpush_users ORDER BY device_id";
$params = array(); $params = array();
} }
else { else {
$sql = "select device_id from zpush_users where username = :username order by device_id"; $sql = "SELECT device_id FROM zpush_users WHERE username = :username ORDER BY device_id";
$params = array(":username" => $username); $params = array(":username" => $username);
} }
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
...@@ -497,7 +497,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -497,7 +497,7 @@ class SqlStateMachine implements IStateMachine {
* @return int * @return int
*/ */
public function GetStateVersion() { public function GetStateVersion() {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetStateVersion()")); ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->GetStateVersion().");
$sth = null; $sth = null;
$record = null; $record = null;
...@@ -506,7 +506,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -506,7 +506,7 @@ class SqlStateMachine implements IStateMachine {
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
$sql = "select key_value from zpush_settings where key_name = :key_name"; $sql = "SELECT key_value FROM zpush_settings WHERE key_name = :key_name";
$params = array(":key_name" => self::VERSION); $params = array(":key_name" => self::VERSION);
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
...@@ -526,7 +526,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -526,7 +526,7 @@ class SqlStateMachine implements IStateMachine {
} }
$this->clearConnection($this->dbh, $sth, $record); $this->clearConnection($this->dbh, $sth, $record);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetStateVersion(): supporting version '%d'", $version));
return $version; return $version;
} }
...@@ -548,7 +548,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -548,7 +548,7 @@ class SqlStateMachine implements IStateMachine {
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
$sql = "select key_value from zpush_settings where key_name = :key_name"; $sql = "SELECT key_value FROM zpush_settings WHERE key_name = :key_name";
$params = array(":key_name" => self::VERSION); $params = array(":key_name" => self::VERSION);
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
...@@ -557,7 +557,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -557,7 +557,7 @@ class SqlStateMachine implements IStateMachine {
$record = $sth->fetch(PDO::FETCH_ASSOC); $record = $sth->fetch(PDO::FETCH_ASSOC);
if ($record) { if ($record) {
$sth = null; $sth = null;
$sql = "update zpush_settings set key_value = :value, updated_at = :updated_at where key_name = :key_name"; $sql = "UPDATE zpush_settings SET key_value = :value, updated_at = :updated_at WHERE key_name = :key_name";
$params[":value"] = $version; $params[":value"] = $version;
$params[":updated_at"] = $this->getNow(); $params[":updated_at"] = $this->getNow();
...@@ -568,7 +568,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -568,7 +568,7 @@ class SqlStateMachine implements IStateMachine {
} }
else { else {
$sth = null; $sth = null;
$sql = "insert into zpush_settings (key_name, key_value, created_at, updated_at) values (:key_name, :value, :created_at, :updated_at)"; $sql = "INSERT INTO zpush_settings (key_name, key_value, created_at, updated_at) VALUES (:key_name, :value, :created_at, :updated_at)";
$params[":value"] = $version; $params[":value"] = $version;
$params[":updated_at"] = $params[":created_at"] = $this->getNow(); $params[":updated_at"] = $params[":created_at"] = $this->getNow();
...@@ -605,7 +605,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -605,7 +605,7 @@ class SqlStateMachine implements IStateMachine {
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
$sql = "select state_type, uuid, counter from zpush_states where device_id = :devid order by id_state"; $sql = "SELECT state_type, uuid, counter FROM zpush_states WHERE device_id = :devid ORDER BY id_state";
$params = array(":devid" => $devid); $params = array(":devid" => $devid);
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
...@@ -659,7 +659,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -659,7 +659,7 @@ class SqlStateMachine implements IStateMachine {
$deviceBlocked = false; $deviceBlocked = false;
// Android PROVISIONING initial step // Android PROVISIONING initial step
// LG-D802 is sending an empty deviceid // LG-D802 is sending an empty deviceid
if ($devid != "validate" && $devid != "") { if ($devid != "validate" && $devid != "") {
$sth = null; $sth = null;
...@@ -668,7 +668,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -668,7 +668,7 @@ class SqlStateMachine implements IStateMachine {
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
$sql = "select count(*) as pcount from zpush_preauth_users where username = :user and device_id != 'authorized' and authorized = 1"; $sql = "SELECT COUNT(*) AS pcount FROM zpush_preauth_users WHERE username = :user AND device_id != 'authorized' AND authorized = 1";
$params = array(":user" => $user); $params = array(":user" => $user);
// Get number of authorized devices for user // Get number of authorized devices for user
...@@ -681,7 +681,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -681,7 +681,7 @@ class SqlStateMachine implements IStateMachine {
$record = null; $record = null;
$sth = null; $sth = null;
$sql = "select authorized from zpush_preauth_users where username = :user and device_id = :devid"; $sql = "SELECT authorized FROM zpush_preauth_users WHERE username = :user AND device_id = :devid";
$params = array(":user" => $user, ":devid" => "authorized"); $params = array(":user" => $user, ":devid" => "authorized");
$paramsNewDevid = array(); $paramsNewDevid = array();
$paramsNewUser = array(); $paramsNewUser = array();
...@@ -779,14 +779,14 @@ class SqlStateMachine implements IStateMachine { ...@@ -779,14 +779,14 @@ class SqlStateMachine implements IStateMachine {
if (count($paramsNewUser) > 0) { if (count($paramsNewUser) > 0) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetUserDevicePermission(): Creating new user '%s'", $user)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetUserDevicePermission(): Creating new user '%s'", $user));
$sql = "insert into zpush_preauth_users (username, device_id, authorized, created_at, updated_at) values (:user, :devid, :auth, :created_at, :updated_at)"; $sql = "INSERT INTO zpush_preauth_users (username, device_id, authorized, created_at, updated_at) VALUES (:user, :devid, :auth, :created_at, :updated_at)";
$paramsNewUser[":user"] = $user; $paramsNewUser[":user"] = $user;
$paramsNewUser[":devid"] = "authorized"; $paramsNewUser[":devid"] = "authorized";
$paramsNewUser[":created_at"] = $paramsNewUser[":updated_at"] = $this->getNow(); $paramsNewUser[":created_at"] = $paramsNewUser[":updated_at"] = $this->getNow();
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
if (!$sth->execute($paramsNewUser)) { if (!$sth->execute($paramsNewUser)) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->GetUserDevicePermission(): Error creating new user")); ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->GetUserDevicePermission(): Error creating new user %s", print_r($sth->errorInfo(), 1)));
$status = SYNC_COMMONSTATUS_USERDISABLEDFORSYNC; $status = SYNC_COMMONSTATUS_USERDISABLEDFORSYNC;
} }
} }
...@@ -794,14 +794,14 @@ class SqlStateMachine implements IStateMachine { ...@@ -794,14 +794,14 @@ class SqlStateMachine implements IStateMachine {
if (count($paramsNewDevid) > 0) { if (count($paramsNewDevid) > 0) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetUserDevicePermission(): Creating new device '%s' for user '%s'", $devid, $user)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->GetUserDevicePermission(): Creating new device '%s' for user '%s'", $devid, $user));
$sql = "insert into zpush_preauth_users (username, device_id, authorized, created_at, updated_at) values (:user, :devid, :auth, :created_at, :updated_at)"; $sql = "INSERT INTO zpush_preauth_users (username, device_id, authorized, created_at, updated_at) VALUES (:user, :devid, :auth, :created_at, :updated_at)";
$paramsNewDevid[":user"] = $user; $paramsNewDevid[":user"] = $user;
$paramsNewDevid[":devid"] = $devid; $paramsNewDevid[":devid"] = $devid;
$paramsNewDevid[":created_at"] = $paramsNewDevid[":updated_at"] = $this->getNow(); $paramsNewDevid[":created_at"] = $paramsNewDevid[":updated_at"] = $this->getNow();
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
if (!$sth->execute($paramsNewDevid)) { if (!$sth->execute($paramsNewDevid)) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->GetUserDevicePermission(): Error creating user new device")); ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->GetUserDevicePermission(): Error creating user new device %s", print_r($sth->errorInfo(), 1)));
$status = SYNC_COMMONSTATUS_USERDISABLEDFORSYNC; $status = SYNC_COMMONSTATUS_USERDISABLEDFORSYNC;
} }
} }
...@@ -835,7 +835,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -835,7 +835,7 @@ class SqlStateMachine implements IStateMachine {
$params = array("user" => $username, "backend" => $backend); $params = array("user" => $username, "backend" => $backend);
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
if ($sth->execute($params) === false) { if ($sth->execute($params) === false) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->GetMappedUsername(): Failed to execute query")); ZLog::Write(LOGLEVEL_ERROR, "SqlStateMachine->GetMappedUsername(): Failed to execute query %s", print_r($sth->errorInfo(), 1));
} else if ($record = $sth->fetch(PDO::FETCH_ASSOC)) { } else if ($record = $sth->fetch(PDO::FETCH_ASSOC)) {
$result = $record["mappedname"]; $result = $record["mappedname"];
} }
...@@ -866,7 +866,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -866,7 +866,7 @@ class SqlStateMachine implements IStateMachine {
$params = array("user" => $username, "backend" => $backend, "mappedname" => $mappedname, "mappedname2" => $mappedname); $params = array("user" => $username, "backend" => $backend, "mappedname" => $mappedname, "mappedname2" => $mappedname);
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
if ($sth->execute($params) === false) { if ($sth->execute($params) === false) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->MapUsername(): Failed to execute query")); ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->MapUsername(): Failed to execute query %s", print_r($sth->errorInfo(), 1)));
return false; return false;
} }
...@@ -890,10 +890,10 @@ class SqlStateMachine implements IStateMachine { ...@@ -890,10 +890,10 @@ class SqlStateMachine implements IStateMachine {
$params = array("user" => $username, "backend" => $backend); $params = array("user" => $username, "backend" => $backend);
$sth = $this->dbh->prepare($sql); $sth = $this->dbh->prepare($sql);
if ($sth->execute($params) === false) { if ($sth->execute($params) === false) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->UnmapUsername(): Failed to execute query")); ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->UnmapUsername(): Failed to execute query %s", print_r($sth->errorInfo(), 1)));
return false; return false;
} else if ($sth->rowCount() !== 1) { } else if ($sth->rowCount() !== 1) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->MapUsername(): Invalid mapping of username and backend")); ZLog::Write(LOGLEVEL_ERROR, sprintf("SqlStateMachine->UnmapUsername(): Invalid mapping of username and backend. Found %s user name->backend mappings", $sth->rowCount()));
return false; return false;
} }
...@@ -995,7 +995,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -995,7 +995,7 @@ class SqlStateMachine implements IStateMachine {
* @throws RuntimeException * @throws RuntimeException
*/ */
private function createDB() { private function createDB() {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SqlStateMachine->createDB(): %s database is not available, trying to create it.", STATE_SQL_DATABASE)); ZLog::Write(LOGLEVEL_INFO, sprintf("SqlStateMachine->createDB(): %s database is not available, trying to create it.", STATE_SQL_DATABASE));
$dsn = sprintf("%s:host=%s;port=%s", STATE_SQL_ENGINE, STATE_SQL_SERVER, STATE_SQL_PORT); $dsn = sprintf("%s:host=%s;port=%s", STATE_SQL_ENGINE, STATE_SQL_SERVER, STATE_SQL_PORT);
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
...@@ -1019,7 +1019,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -1019,7 +1019,7 @@ class SqlStateMachine implements IStateMachine {
* @throws RuntimeException * @throws RuntimeException
*/ */
private function createTables() { private function createTables() {
ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->createTables(): tables are not available, trying to create them."); ZLog::Write(LOGLEVEL_INFO, "SqlStateMachine->createTables(): tables are not available, trying to create them.");
$dsn = sprintf("%s:host=%s;port=%s;dbname=%s", STATE_SQL_ENGINE, STATE_SQL_SERVER, STATE_SQL_PORT, STATE_SQL_DATABASE); $dsn = sprintf("%s:host=%s;port=%s;dbname=%s", STATE_SQL_ENGINE, STATE_SQL_SERVER, STATE_SQL_PORT, STATE_SQL_DATABASE);
try { try {
$this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options); $this->dbh = new PDO($dsn, STATE_SQL_USER, STATE_SQL_PASSWORD, $this->options);
...@@ -1030,12 +1030,12 @@ class SqlStateMachine implements IStateMachine { ...@@ -1030,12 +1030,12 @@ class SqlStateMachine implements IStateMachine {
return true; return true;
} }
catch (PDOException $ex) { catch (PDOException $ex) {
throw new RuntimeException(sprintf("SqlStateMachine->checkDbAndTables(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage())); throw new RuntimeException(sprintf("SqlStateMachine->createTables(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
} }
} }
/** /**
* Checks if state tables have data. * Checks if state tables have data. This is only used by the migrate-filestates-to-db script.
* *
* @access public * @access public
* @return boolean * @return boolean
...@@ -1078,7 +1078,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -1078,7 +1078,7 @@ class SqlStateMachine implements IStateMachine {
return false; return false;
} }
catch (PDOException $ex) { catch (PDOException $ex) {
throw new RuntimeException(sprintf("SqlStateMachine->checkDbAndTables(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage())); throw new RuntimeException(sprintf("SqlStateMachine->checkTablesHaveData(): PDOException (%s): %s", $ex->getCode(), $ex->getMessage()));
} }
return false; return 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