From 18180ef092fde1e74a92c63d3bb01ce0093d2152 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Fri, 11 Nov 2016 18:08:17 -0500 Subject: [PATCH 1/2] Allow late static binding of DataConnector Class constants in DataConnector_pdo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed “DataConnector::” to “static::” --- .../DataConnector/DataConnector_pdo.php | 134 +++++++++--------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/src/ToolProvider/DataConnector/DataConnector_pdo.php b/src/ToolProvider/DataConnector/DataConnector_pdo.php index 3528aca..b710f53 100644 --- a/src/ToolProvider/DataConnector/DataConnector_pdo.php +++ b/src/ToolProvider/DataConnector/DataConnector_pdo.php @@ -61,7 +61,7 @@ public function loadToolConsumer($consumer) 'consumer_name, consumer_version, consumer_guid, ' . 'profile, tool_proxy, settings, protected, enabled, ' . 'enable_from, enable_until, last_access, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' . 'WHERE consumer_pk = :id'; $query = $this->db->prepare($sql); $id = $consumer->getRecordId(); @@ -71,10 +71,10 @@ public function loadToolConsumer($consumer) 'consumer_name, consumer_version, consumer_guid, ' . 'profile, tool_proxy, settings, protected, enabled, ' . 'enable_from, enable_until, last_access, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' . 'WHERE consumer_key256 = :key256'; $query = $this->db->prepare($sql); - $key256 = DataConnector::getConsumerKey($consumer->getKey()); + $key256 = static::getConsumerKey($consumer->getKey()); $query->bindValue('key256', $key256, PDO::PARAM_STR); } @@ -158,7 +158,7 @@ public function saveToolConsumer($consumer) $last = date($this->dateFormat, $consumer->lastAccess); } if (empty($id)) { - $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' (consumer_key256, consumer_key, name, ' . + $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' (consumer_key256, consumer_key, name, ' . 'secret, lti_version, consumer_name, consumer_version, consumer_guid, profile, tool_proxy, settings, protected, enabled, ' . 'enable_from, enable_until, last_access, created, updated) ' . 'VALUES (:key256, :key, :name, :secret, :lti_version, :consumer_name, :consumer_version, :consumer_guid, :profile, :tool_proxy, :settings, ' . @@ -183,7 +183,7 @@ public function saveToolConsumer($consumer) $query->bindValue('created', $now, PDO::PARAM_STR); $query->bindValue('updated', $now, PDO::PARAM_STR); } else { - $sql = 'UPDATE ' . $this->dbTableNamePrefix . DataConnector::CONSUMER_TABLE_NAME . ' ' . + $sql = 'UPDATE ' . $this->dbTableNamePrefix . static::CONSUMER_TABLE_NAME . ' ' . 'SET consumer_key256 = :key256, consumer_key = :key, name = :name, secret = :secret, lti_version = :lti_version, ' . 'consumer_name = :consumer_name, consumer_version = :consumer_version, consumer_guid = :consumer_guid, ' . 'profile = :profile, tool_proxy = :tool_proxy, settings = :settings, ' . @@ -235,15 +235,15 @@ public function deleteToolConsumer($consumer) $id = $consumer->getRecordId(); // Delete any nonce values for this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' WHERE consumer_pk = :id'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any outstanding share keys for resource links for this consumer $sql = 'DELETE sk ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . 'WHERE rl.consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -251,9 +251,9 @@ public function deleteToolConsumer($consumer) // Delete any outstanding share keys for resource links for contexts in this consumer $sql = 'DELETE sk ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . 'WHERE c.consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -261,8 +261,8 @@ public function deleteToolConsumer($consumer) // Delete any users in resource links for this consumer $sql = 'DELETE u ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . 'WHERE rl.consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -270,17 +270,17 @@ public function deleteToolConsumer($consumer) // Delete any users in resource links for contexts in this consumer $sql = 'DELETE u ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . 'WHERE c.consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Update any resource links for which this consumer is acting as a primary resource link - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' prl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' prl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . 'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' . 'WHERE rl.consumer_pk = :id'; $query = $this->db->prepare($sql); @@ -288,9 +288,9 @@ public function deleteToolConsumer($consumer) $query->execute(); // Update any resource links for contexts in which this consumer is acting as a primary resource link - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' prl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' prl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . 'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' . 'WHERE c.consumer_pk = :id'; $query = $this->db->prepare($sql); @@ -299,7 +299,7 @@ public function deleteToolConsumer($consumer) // Delete any resource links for this consumer $sql = 'DELETE rl ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . 'WHERE rl.consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -307,8 +307,8 @@ public function deleteToolConsumer($consumer) // Delete any resource links for contexts in this consumer $sql = 'DELETE rl ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . 'WHERE c.consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -316,7 +316,7 @@ public function deleteToolConsumer($consumer) // Delete any contexts for this consumer $sql = 'DELETE c ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ' . + "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ' . 'WHERE c.consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -324,7 +324,7 @@ public function deleteToolConsumer($consumer) // Delete consumer $sql = 'DELETE c ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' c ' . + "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' c ' . 'WHERE c.consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -350,7 +350,7 @@ public function getToolConsumers() 'consumer_name, consumer_version, consumer_guid, ' . 'profile, tool_proxy, settings, protected, enabled, ' . 'enable_from, enable_until, last_access, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' . 'ORDER BY name'; $query = $this->db->prepare($sql); $ok = ($query !== FALSE); @@ -453,13 +453,13 @@ public function loadContext($context) $ok = false; if (!empty($context->getRecordId())) { $sql = 'SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' . 'WHERE (context_pk = :id)'; $query = $this->db->prepare($sql); $query->bindValue('id', $context->getRecordId(), PDO::PARAM_INT); } else { $sql = 'SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' . 'WHERE (consumer_pk = :cid) AND (lti_context_id = :ctx)'; $query = $this->db->prepare($sql); $query->bindValue('cid', $context->getConsumer()->getRecordId(), PDO::PARAM_INT); @@ -504,7 +504,7 @@ public function saveContext($context) $id = $context->getRecordId(); $consumer_pk = $context->getConsumer()->getRecordId(); if (empty($id)) { - $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' (consumer_pk, lti_context_id, ' . + $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' (consumer_pk, lti_context_id, ' . 'settings, created, updated) ' . 'VALUES (:cid, :ctx, :settings, :created, :updated)'; $query = $this->db->prepare($sql); @@ -514,7 +514,7 @@ public function saveContext($context) $query->bindValue('created', $now, PDO::PARAM_STR); $query->bindValue('updated', $now, PDO::PARAM_STR); } else { - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' SET ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' SET ' . 'lti_context_id = :ctx, settings = :settings, '. 'updated = :updated ' . 'WHERE (consumer_pk = :cid) AND (context_pk = :ctxid)'; @@ -552,8 +552,8 @@ public function deleteContext($context) // Delete any outstanding share keys for resource links for this context $sql = 'DELETE sk ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . 'WHERE rl.context_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -561,16 +561,16 @@ public function deleteContext($context) // Delete any users in resource links for this context $sql = 'DELETE u ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . 'WHERE rl.context_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Update any resource links for which this consumer is acting as a primary resource link - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' prl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' prl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . 'SET prl.primary_resource_link_pk = null, prl.share_approved = null ' . 'WHERE rl.context_pk = :id'; $query = $this->db->prepare($sql); @@ -579,7 +579,7 @@ public function deleteContext($context) // Delete any resource links for this consumer $sql = 'DELETE rl ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . 'WHERE rl.context_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -587,7 +587,7 @@ public function deleteContext($context) // Delete context $sql = 'DELETE c ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ' . + "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ' . 'WHERE c.context_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -617,21 +617,21 @@ public function loadResourceLink($resourceLink) if (!empty($resourceLink->getRecordId())) { $sql = 'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = :id)'; $query = $this->db->prepare($sql); $query->bindValue('id', $resourceLink->getRecordId(), PDO::PARAM_INT); } else if (!empty($resourceLink->getContext())) { $sql = 'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (context_pk = :id) AND (lti_resource_link_id = :rlid)'; $query = $this->db->prepare($sql); $query->bindValue('id', $resourceLink->getContext()->getRecordId(), PDO::PARAM_INT); $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR); } else { $sql = 'SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' . - $this->dbTableNamePrefix . DataConnector::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' . + $this->dbTableNamePrefix . static::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' . ' WHERE ((r.consumer_pk = :id1) OR (c.consumer_pk = :id2)) AND (lti_resource_link_id = :rlid)'; $query = $this->db->prepare($sql); $query->bindValue('id1', $resourceLink->getConsumer()->getRecordId(), PDO::PARAM_INT); @@ -706,7 +706,7 @@ public function saveResourceLink($resourceLink) { } $id = $resourceLink->getRecordId(); if (empty($id)) { - $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' . + $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' . 'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' . 'VALUES (:cid, :ctx, :rlid, :settings, :prlid, :share_approved, :created, :updated)'; $query = $this->db->prepare($sql); @@ -719,7 +719,7 @@ public function saveResourceLink($resourceLink) { $query->bindValue('created', $now, PDO::PARAM_STR); $query->bindValue('updated', $now, PDO::PARAM_STR); } else if (!is_null($contextId)) { - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' SET ' . 'consumer_pk = NULL, context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, '. 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' . 'WHERE (resource_link_pk = :id)'; @@ -732,7 +732,7 @@ public function saveResourceLink($resourceLink) { $query->bindValue('updated', $now, PDO::PARAM_STR); $query->bindValue('id', $id, PDO::PARAM_INT); } else { - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' SET ' . 'context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, '. 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' . 'WHERE (consumer_pk = :cid) AND (resource_link_pk = :id)'; @@ -772,7 +772,7 @@ public function deleteResourceLink($resourceLink) $id = $resourceLink->getRecordId(); // Delete any outstanding share keys for resource links for this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = :id)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -780,7 +780,7 @@ public function deleteResourceLink($resourceLink) // Delete users if ($ok) { - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = :id)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -789,7 +789,7 @@ public function deleteResourceLink($resourceLink) // Update any resource links for which this is the primary resource link if ($ok) { - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'SET primary_resource_link_pk = NULL ' . 'WHERE (primary_resource_link_pk = :id)'; $query = $this->db->prepare($sql); @@ -799,7 +799,7 @@ public function deleteResourceLink($resourceLink) // Delete resource link if ($ok) { - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = :id)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -834,16 +834,16 @@ public function getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $ if ($localOnly) { $sql = 'SELECT u.user_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' AS u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' AS rl ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' AS u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' AS rl ' . 'ON u.resource_link_pk = rl.resource_link_pk ' . 'WHERE (rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); } else { $sql = 'SELECT u.user_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' AS u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' AS rl ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' AS u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' AS rl ' . 'ON u.resource_link_pk = rl.resource_link_pk ' . 'WHERE ((rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)) OR ' . '((rl.primary_resource_link_pk = :pid) AND (share_approved = 1))'; @@ -882,7 +882,7 @@ public function getSharesResourceLink($resourceLink) $shares = array(); $sql = 'SELECT consumer_pk, resource_link_pk, share_approved ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (primary_resource_link_pk = :id) ' . 'ORDER BY consumer_pk'; $query = $this->db->prepare($sql); @@ -920,7 +920,7 @@ public function loadConsumerNonce($nonce) // Delete any expired nonce values $now = date("{$this->dateFormat} {$this->timeFormat}", time()); - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' WHERE expires <= :now'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE expires <= :now'; $query = $this->db->prepare($sql); $query->bindValue('now', $now, PDO::PARAM_STR); $query->execute(); @@ -928,7 +928,7 @@ public function loadConsumerNonce($nonce) // Load the nonce $id = $nonce->getConsumer()->getRecordId(); $value = $nonce->getValue(); - $sql = "SELECT value T FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' WHERE (consumer_pk = :id) AND (value = :value)'; + $sql = "SELECT value T FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE (consumer_pk = :id) AND (value = :value)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->bindValue('value', $value, PDO::PARAM_STR); @@ -957,7 +957,7 @@ public function saveConsumerNonce($nonce) $id = $nonce->getConsumer()->getRecordId(); $value = $nonce->getValue(); $expires = date("{$this->dateFormat} {$this->timeFormat}", $nonce->expires); - $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' (consumer_pk, value, expires) VALUES (:id, :value, :expires)'; + $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' (consumer_pk, value, expires) VALUES (:id, :value, :expires)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->bindValue('value', $value, PDO::PARAM_STR); @@ -987,7 +987,7 @@ public function loadResourceLinkShareKey($shareKey) // Clear expired share keys $now = date("{$this->dateFormat} {$this->timeFormat}", time()); - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE expires <= :now'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE expires <= :now'; $query = $this->db->prepare($sql); $query->bindValue('now', $now, PDO::PARAM_STR); $query->execute(); @@ -995,7 +995,7 @@ public function loadResourceLinkShareKey($shareKey) // Load share key $id = $shareKey->getId(); $sql = 'SELECT resource_link_pk, auto_approve, expires ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . 'WHERE share_key_id = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_STR); @@ -1027,7 +1027,7 @@ public function saveResourceLinkShareKey($shareKey) $id = $shareKey->getId(); $expires = date("{$this->dateFormat} {$this->timeFormat}", $shareKey->expires); - $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . '(share_key_id, resource_link_pk, auto_approve, expires) ' . 'VALUES (:id, :prlid, :approve, :expires)'; $query = $this->db->prepare($sql); @@ -1052,7 +1052,7 @@ public function deleteResourceLinkShareKey($shareKey) { $id = $shareKey->getId(); - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE share_key_id = :id'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE share_key_id = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_STR); $ok = $query->execute(); @@ -1084,7 +1084,7 @@ public function loadUser($user) if (!empty($user->getRecordId())) { $id = $user->getRecordId(); $sql = 'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (user_pk = :id)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -1092,7 +1092,7 @@ public function loadUser($user) $id = $user->getResourceLink()->getRecordId(); $uid = $user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY); $sql = 'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = :id) AND (lti_user_id = :uid)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -1129,7 +1129,7 @@ public function saveUser($user) $time = time(); $now = date("{$this->dateFormat} {$this->timeFormat}", $time); if (is_null($user->created)) { - $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' (resource_link_pk, ' . + $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' (resource_link_pk, ' . 'lti_user_id, lti_result_sourcedid, created, updated) ' . 'VALUES (:rlid, :uid, :sourcedid, :created, :updated)'; $query = $this->db->prepare($sql); @@ -1139,7 +1139,7 @@ public function saveUser($user) $query->bindValue('created', $now, PDO::PARAM_STR); $query->bindValue('updated', $now, PDO::PARAM_STR); } else { - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'SET lti_result_sourcedid = :sourcedid, updated = :updated ' . 'WHERE (user_pk = :id)'; $query = $this->db->prepare($sql); @@ -1170,7 +1170,7 @@ public function saveUser($user) public function deleteUser($user) { - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (user_pk = :id)'; $query = $this->db->prepare($sql); $query->bindValue('id', $user->getRecordId(), PDO::PARAM_INT); From 93e28674d69ecff23c7d09dc59ef379cd811d882 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Sun, 27 Nov 2016 15:21:20 -0500 Subject: [PATCH 2/2] Updated other DataConnector classes Applied the same DataConnector:: to static:: fix for mysql and sqlite classes. --- .../DataConnector/DataConnector_mysql.php | 212 +++++++++--------- .../DataConnector_pdo_sqlite.php | 78 +++---- 2 files changed, 145 insertions(+), 145 deletions(-) diff --git a/src/ToolProvider/DataConnector/DataConnector_mysql.php b/src/ToolProvider/DataConnector/DataConnector_mysql.php index c0dc1ce..7855f5e 100644 --- a/src/ToolProvider/DataConnector/DataConnector_mysql.php +++ b/src/ToolProvider/DataConnector/DataConnector_mysql.php @@ -48,18 +48,18 @@ public function loadToolConsumer($consumer) 'consumer_name, consumer_version, consumer_guid, ' . 'profile, tool_proxy, settings, protected, enabled, ' . 'enable_from, enable_until, last_access, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' . "WHERE consumer_pk = %d", $consumer->getRecordId()); } else { - $key256 = DataConnector::getConsumerKey($consumer->getKey()); + $key256 = static::getConsumerKey($consumer->getKey()); $sql = sprintf('SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' . 'consumer_name, consumer_version, consumer_guid, ' . 'profile, tool_proxy, settings, protected, enabled, ' . 'enable_from, enable_until, last_access, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' . "WHERE consumer_key256 = %s", - DataConnector::quoted($key256)); + static::quoted($key256)); } $rsConsumer = mysql_query($sql); if ($rsConsumer) { @@ -119,7 +119,7 @@ public function saveToolConsumer($consumer) $id = $consumer->getRecordId(); $key = $consumer->getKey(); - $key256 = DataConnector::getConsumerKey($key); + $key256 = static::getConsumerKey($key); if ($key === $key256) { $key = null; } @@ -142,31 +142,31 @@ public function saveToolConsumer($consumer) $last = date($this->dateFormat, $consumer->lastAccess); } if (empty($id)) { - $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' (consumer_key256, consumer_key, name, ' . + $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' (consumer_key256, consumer_key, name, ' . 'secret, lti_version, consumer_name, consumer_version, consumer_guid, profile, tool_proxy, settings, protected, enabled, ' . 'enable_from, enable_until, last_access, created, updated) ' . 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %s, %s, %s, %s, %s)', - DataConnector::quoted($key256), DataConnector::quoted($key), DataConnector::quoted($consumer->name), - DataConnector::quoted($consumer->secret), DataConnector::quoted($consumer->ltiVersion), - DataConnector::quoted($consumer->consumerName), DataConnector::quoted($consumer->consumerVersion), DataConnector::quoted($consumer->consumerGuid), - DataConnector::quoted($profile), DataConnector::quoted($consumer->toolProxy), DataConnector::quoted($settingsValue), - $protected, $enabled, DataConnector::quoted($from), DataConnector::quoted($until), DataConnector::quoted($last), - DataConnector::quoted($now), DataConnector::quoted($now)); + static::quoted($key256), static::quoted($key), static::quoted($consumer->name), + static::quoted($consumer->secret), static::quoted($consumer->ltiVersion), + static::quoted($consumer->consumerName), static::quoted($consumer->consumerVersion), static::quoted($consumer->consumerGuid), + static::quoted($profile), static::quoted($consumer->toolProxy), static::quoted($settingsValue), + $protected, $enabled, static::quoted($from), static::quoted($until), static::quoted($last), + static::quoted($now), static::quoted($now)); } else { - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' SET ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' SET ' . 'consumer_key256 = %s, consumer_key = %s, ' . 'name = %s, secret= %s, lti_version = %s, consumer_name = %s, consumer_version = %s, consumer_guid = %s, ' . 'profile = %s, tool_proxy = %s, settings = %s, ' . 'protected = %d, enabled = %d, enable_from = %s, enable_until = %s, last_access = %s, updated = %s ' . 'WHERE consumer_pk = %d', - DataConnector::quoted($key256), DataConnector::quoted($key), - DataConnector::quoted($consumer->name), - DataConnector::quoted($consumer->secret), DataConnector::quoted($consumer->ltiVersion), - DataConnector::quoted($consumer->consumerName), DataConnector::quoted($consumer->consumerVersion), DataConnector::quoted($consumer->consumerGuid), - DataConnector::quoted($profile), DataConnector::quoted($consumer->toolProxy), DataConnector::quoted($settingsValue), + static::quoted($key256), static::quoted($key), + static::quoted($consumer->name), + static::quoted($consumer->secret), static::quoted($consumer->ltiVersion), + static::quoted($consumer->consumerName), static::quoted($consumer->consumerVersion), static::quoted($consumer->consumerGuid), + static::quoted($profile), static::quoted($consumer->toolProxy), static::quoted($settingsValue), $protected, $enabled, - DataConnector::quoted($from), DataConnector::quoted($until), DataConnector::quoted($last), - DataConnector::quoted($now), $consumer->getRecordId()); + static::quoted($from), static::quoted($until), static::quoted($last), + static::quoted($now), $consumer->getRecordId()); } $ok = mysql_query($sql); if ($ok) { @@ -192,56 +192,56 @@ public function deleteToolConsumer($consumer) { // Delete any nonce values for this consumer - $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' WHERE consumer_pk = %d', + $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE consumer_pk = %d', $consumer->getRecordId()); mysql_query($sql); // Delete any outstanding share keys for resource links for this consumer $sql = sprintf('DELETE sk ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . 'WHERE rl.consumer_pk = %d', $consumer->getRecordId()); mysql_query($sql); // Delete any outstanding share keys for resource links for contexts in this consumer $sql = sprintf('DELETE sk ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . 'WHERE c.consumer_pk = %d', $consumer->getRecordId()); mysql_query($sql); // Delete any users in resource links for this consumer $sql = sprintf('DELETE u ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . 'WHERE rl.consumer_pk = %d', $consumer->getRecordId()); mysql_query($sql); // Delete any users in resource links for contexts in this consumer $sql = sprintf('DELETE u ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . 'WHERE c.consumer_pk = %d', $consumer->getRecordId()); mysql_query($sql); // Update any resource links for which this consumer is acting as a primary resource link - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' prl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' prl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . 'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' . 'WHERE rl.consumer_pk = %d', $consumer->getRecordId()); $ok = mysql_query($sql); // Update any resource links for contexts in which this consumer is acting as a primary resource link - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' prl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' prl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . 'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' . 'WHERE c.consumer_pk = %d', $consumer->getRecordId()); @@ -249,29 +249,29 @@ public function deleteToolConsumer($consumer) // Delete any resource links for this consumer $sql = sprintf('DELETE rl ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . 'WHERE rl.consumer_pk = %d', $consumer->getRecordId()); mysql_query($sql); // Delete any resource links for contexts in this consumer $sql = sprintf('DELETE rl ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . 'WHERE c.consumer_pk = %d', $consumer->getRecordId()); mysql_query($sql); // Delete any contexts for this consumer $sql = sprintf('DELETE c ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ' . + "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ' . 'WHERE c.consumer_pk = %d', $consumer->getRecordId()); mysql_query($sql); // Delete consumer $sql = sprintf('DELETE c ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' c ' . + "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' c ' . 'WHERE c.consumer_pk = %d', $consumer->getRecordId()); $ok = mysql_query($sql); @@ -295,7 +295,7 @@ public function getToolConsumers() $sql = 'SELECT consumer_pk, consumer_key, consumer_key, name, secret, lti_version, consumer_name, consumer_version, consumer_guid, ' . 'profile, tool_proxy, settings, ' . 'protected, enabled, enable_from, enable_until, last_access, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' . 'ORDER BY name'; $rsConsumers = mysql_query($sql); if ($rsConsumers) { @@ -391,14 +391,14 @@ public function loadContext($context) $ok = false; if (!empty($context->getRecordId())) { $sql = sprintf('SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' . 'WHERE (context_pk = %d)', $context->getRecordId()); } else { $sql = sprintf('SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' . 'WHERE (consumer_pk = %d) AND (lti_context_id = %s)', - $context->getConsumer()->getRecordId(), DataConnector::quoted($context->ltiContextId)); + $context->getConsumer()->getRecordId(), static::quoted($context->ltiContextId)); } $rs_context = mysql_query($sql); if ($rs_context) { @@ -438,19 +438,19 @@ public function saveContext($context) $id = $context->getRecordId(); $consumer_pk = $context->getConsumer()->getRecordId(); if (empty($id)) { - $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' (consumer_pk, lti_context_id, ' . + $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' (consumer_pk, lti_context_id, ' . 'settings, created, updated) ' . 'VALUES (%d, %s, %s, %s, %s)', - $consumer_pk, DataConnector::quoted($context->ltiContextId), - DataConnector::quoted($settingsValue), - DataConnector::quoted($now), DataConnector::quoted($now)); + $consumer_pk, static::quoted($context->ltiContextId), + static::quoted($settingsValue), + static::quoted($now), static::quoted($now)); } else { - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' SET ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' SET ' . 'lti_context_id = %s, settings = %s, '. 'updated = %s' . 'WHERE (consumer_pk = %d) AND (context_pk = %d)', - DataConnector::quoted($context->ltiContextId), DataConnector::quoted($settingsValue), - DataConnector::quoted($now), $consumer_pk, $id); + static::quoted($context->ltiContextId), static::quoted($settingsValue), + static::quoted($now), $consumer_pk, $id); } $ok = mysql_query($sql); if ($ok) { @@ -477,23 +477,23 @@ public function deleteContext($context) // Delete any outstanding share keys for resource links for this context $sql = sprintf('DELETE sk ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' . 'WHERE rl.context_pk = %d', $context->getRecordId()); mysql_query($sql); // Delete any users in resource links for this context $sql = sprintf('DELETE u ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' . 'WHERE rl.context_pk = %d', $context->getRecordId()); mysql_query($sql); // Update any resource links for which this consumer is acting as a primary resource link - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' prl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' prl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' . 'SET prl.primary_resource_link_pk = null, prl.share_approved = null ' . 'WHERE rl.context_pk = %d', $context->getRecordId()); @@ -501,14 +501,14 @@ public function deleteContext($context) // Delete any resource links for this consumer $sql = sprintf('DELETE rl ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . 'WHERE rl.context_pk = %d', $context->getRecordId()); mysql_query($sql); // Delete context $sql = sprintf('DELETE c ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ', + "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ', 'WHERE c.context_pk = %d', $context->getRecordId()); $ok = mysql_query($sql); @@ -537,20 +537,20 @@ public function loadResourceLink($resourceLink) $ok = false; if (!empty($resourceLink->getRecordId())) { $sql = sprintf('SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = %d)', $resourceLink->getRecordId()); } else if (!empty($resourceLink->getContext())) { $sql = sprintf('SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (context_pk = %d) AND (lti_resource_link_id = %s)', - $resourceLink->getContext()->getRecordId(), DataConnector::quoted($resourceLink->getId())); + $resourceLink->getContext()->getRecordId(), static::quoted($resourceLink->getId())); } else { $sql = sprintf('SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' . - $this->dbTableNamePrefix . DataConnector::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' . + $this->dbTableNamePrefix . static::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' . ' WHERE ((r.consumer_pk = %d) OR (c.consumer_pk = %d)) AND (lti_resource_link_id = %s)', - $resourceLink->getConsumer()->getRecordId(), $resourceLink->getConsumer()->getRecordId(), DataConnector::quoted($resourceLink->getId())); + $resourceLink->getConsumer()->getRecordId(), $resourceLink->getConsumer()->getRecordId(), static::quoted($resourceLink->getId())); } $rsContext = mysql_query($sql); if ($rsContext) { @@ -625,27 +625,27 @@ public function saveResourceLink($resourceLink) { } $id = $resourceLink->getRecordId(); if (empty($id)) { - $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' . + $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' . 'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' . 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', - $consumerId, $contextId, DataConnector::quoted($resourceLink->getId()), - DataConnector::quoted($settingsValue), - $primaryResourceLinkId, $approved, DataConnector::quoted($now), DataConnector::quoted($now)); + $consumerId, $contextId, static::quoted($resourceLink->getId()), + static::quoted($settingsValue), + $primaryResourceLinkId, $approved, static::quoted($now), static::quoted($now)); } else if ($contextId !== 'NULL') { - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' SET ' . 'consumer_pk = %s, lti_resource_link_id = %s, settings = %s, '. 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' . 'WHERE (context_pk = %s) AND (resource_link_pk = %d)', - $consumerId, DataConnector::quoted($resourceLink->getId()), - DataConnector::quoted($settingsValue), $primaryResourceLinkId, $approved, DataConnector::quoted($now), + $consumerId, static::quoted($resourceLink->getId()), + static::quoted($settingsValue), $primaryResourceLinkId, $approved, static::quoted($now), $contextId, $id); } else { - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' SET ' . 'context_pk = %s, lti_resource_link_id = %s, settings = %s, '. 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' . 'WHERE (consumer_pk = %s) AND (resource_link_pk = %d)', - $contextId, DataConnector::quoted($resourceLink->getId()), - DataConnector::quoted($settingsValue), $primaryResourceLinkId, $approved, DataConnector::quoted($now), + $contextId, static::quoted($resourceLink->getId()), + static::quoted($settingsValue), $primaryResourceLinkId, $approved, static::quoted($now), $consumerId, $id); } $ok = mysql_query($sql); @@ -672,14 +672,14 @@ public function deleteResourceLink($resourceLink) { // Delete any outstanding share keys for resource links for this consumer - $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = %d)', $resourceLink->getRecordId()); $ok = mysql_query($sql); // Delete users if ($ok) { - $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = %d)', $resourceLink->getRecordId()); $ok = mysql_query($sql); @@ -687,7 +687,7 @@ public function deleteResourceLink($resourceLink) // Update any resource links for which this is the primary resource link if ($ok) { - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'SET primary_resource_link_pk = NULL ' . 'WHERE (primary_resource_link_pk = %d)', $resourceLink->getRecordId()); @@ -696,7 +696,7 @@ public function deleteResourceLink($resourceLink) // Delete resource link if ($ok) { - $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = %s)', $resourceLink->getRecordId()); $ok = mysql_query($sql); @@ -729,15 +729,15 @@ public function getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $ if ($localOnly) { $sql = sprintf('SELECT u.user_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' AS u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' AS rl ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' AS u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' AS rl ' . 'ON u.resource_link_pk = rl.resource_link_pk ' . "WHERE (rl.resource_link_pk = %d) AND (rl.primary_resource_link_pk IS NULL)", $resourceLink->getRecordId()); } else { $sql = sprintf('SELECT u.user_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' AS u ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' AS rl ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' AS u ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' AS rl ' . 'ON u.resource_link_pk = rl.resource_link_pk ' . 'WHERE ((rl.resource_link_pk = %d) AND (rl.primary_resource_link_pk IS NULL)) OR ' . '((rl.primary_resource_link_pk = %d) AND (share_approved = 1))', @@ -776,7 +776,7 @@ public function getSharesResourceLink($resourceLink) $shares = array(); $sql = sprintf('SELECT consumer_pk, resource_link_pk, share_approved ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (primary_resource_link_pk = %d) ' . 'ORDER BY consumer_pk', $resourceLink->getRecordId()); @@ -813,12 +813,12 @@ public function loadConsumerNonce($nonce) // Delete any expired nonce values $now = date("{$this->dateFormat} {$this->timeFormat}", time()); - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . " WHERE expires <= '{$now}'"; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . " WHERE expires <= '{$now}'"; mysql_query($sql); // Load the nonce - $sql = sprintf("SELECT value AS T FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' WHERE (consumer_pk = %d) AND (value = %s)', - $nonce->getConsumer()->getRecordId(), DataConnector::quoted($nonce->getValue())); + $sql = sprintf("SELECT value AS T FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE (consumer_pk = %d) AND (value = %s)', + $nonce->getConsumer()->getRecordId(), static::quoted($nonce->getValue())); $rs_nonce = mysql_query($sql); if ($rs_nonce) { $row = mysql_fetch_object($rs_nonce); @@ -842,9 +842,9 @@ public function saveConsumerNonce($nonce) { $expires = date("{$this->dateFormat} {$this->timeFormat}", $nonce->expires); - $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . " (consumer_pk, value, expires) VALUES (%d, %s, %s)", - $nonce->getConsumer()->getRecordId(), DataConnector::quoted($nonce->getValue()), - DataConnector::quoted($expires)); + $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . " (consumer_pk, value, expires) VALUES (%d, %s, %s)", + $nonce->getConsumer()->getRecordId(), static::quoted($nonce->getValue()), + static::quoted($expires)); $ok = mysql_query($sql); return $ok; @@ -870,13 +870,13 @@ public function loadResourceLinkShareKey($shareKey) // Clear expired share keys $now = date("{$this->dateFormat} {$this->timeFormat}", time()); - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . " WHERE expires <= '{$now}'"; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . " WHERE expires <= '{$now}'"; mysql_query($sql); // Load share key $id = mysql_real_escape_string($shareKey->getId()); $sql = 'SELECT resource_link_pk, auto_approve, expires ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . "WHERE share_key_id = '{$id}'"; $rsShareKey = mysql_query($sql); if ($rsShareKey) { @@ -908,10 +908,10 @@ public function saveResourceLinkShareKey($shareKey) $approve = 0; } $expires = date("{$this->dateFormat} {$this->timeFormat}", $shareKey->expires); - $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . '(share_key_id, resource_link_pk, auto_approve, expires) ' . "VALUES (%s, %d, {$approve}, '{$expires}')", - DataConnector::quoted($shareKey->getId()), $shareKey->resourceLinkId); + static::quoted($shareKey->getId()), $shareKey->resourceLinkId); $ok = mysql_query($sql); return $ok; @@ -928,7 +928,7 @@ public function saveResourceLinkShareKey($shareKey) public function deleteResourceLinkShareKey($shareKey) { - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . " WHERE share_key_id = '{$shareKey->getId()}'"; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . " WHERE share_key_id = '{$shareKey->getId()}'"; $ok = mysql_query($sql); @@ -958,15 +958,15 @@ public function loadUser($user) $ok = false; if (!empty($user->getRecordId())) { $sql = sprintf('SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (user_pk = %d)', $user->getRecordId()); } else { $sql = sprintf('SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . - "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = %d) AND (lti_user_id = %s)', $user->getResourceLink()->getRecordId(), - DataConnector::quoted($user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY))); + static::quoted($user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY))); } $rsUser = mysql_query($sql); if ($rsUser) { @@ -999,18 +999,18 @@ public function saveUser($user) $time = time(); $now = date("{$this->dateFormat} {$this->timeFormat}", $time); if (is_null($user->created)) { - $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' (resource_link_pk, ' . + $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' (resource_link_pk, ' . 'lti_user_id, lti_result_sourcedid, created, updated) ' . 'VALUES (%d, %s, %s, %s, %s)', $user->getResourceLink()->getRecordId(), - DataConnector::quoted($user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY)), DataConnector::quoted($user->ltiResultSourcedId), - DataConnector::quoted($now), DataConnector::quoted($now)); + static::quoted($user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY)), static::quoted($user->ltiResultSourcedId), + static::quoted($now), static::quoted($now)); } else { - $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'SET lti_result_sourcedid = %s, updated = %s ' . 'WHERE (user_pk = %d)', - DataConnector::quoted($user->ltiResultSourcedId), - DataConnector::quoted($now), + static::quoted($user->ltiResultSourcedId), + static::quoted($now), $user->getRecordId()); } $ok = mysql_query($sql); @@ -1036,7 +1036,7 @@ public function saveUser($user) public function deleteUser($user) { - $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . + $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (user_pk = %d)', $user->getRecordId()); $ok = mysql_query($sql); diff --git a/src/ToolProvider/DataConnector/DataConnector_pdo_sqlite.php b/src/ToolProvider/DataConnector/DataConnector_pdo_sqlite.php index 93f03b3..72b35ba 100644 --- a/src/ToolProvider/DataConnector/DataConnector_pdo_sqlite.php +++ b/src/ToolProvider/DataConnector/DataConnector_pdo_sqlite.php @@ -38,88 +38,88 @@ public function deleteToolConsumer($consumer) $id = $consumer->getRecordId(); // Delete any nonce values for this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' WHERE consumer_pk = :id'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any outstanding share keys for resource links for this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "WHERE ({$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any outstanding share keys for resource links for contexts in this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "WHERE ({$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any users in resource links for this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "WHERE ({$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any users in resource links for contexts in this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "WHERE ({$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Update any resource links for which this consumer is acting as a primary resource link - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'SET primary_resource_link_pk = NULL, share_approved = NULL ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))'; + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "WHERE ({$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Update any resource links for contexts in which this consumer is acting as a primary resource link - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'SET primary_resource_link_pk = NULL, share_approved = NULL ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))'; + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' . + "WHERE ({$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any resource links for this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any resource links for contexts in this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . '.context_pk = c.context_pk) AND (c.consumer_pk = :id))'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ' . + "WHERE ({$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . '.context_pk = c.context_pk) AND (c.consumer_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any contexts for this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' . 'WHERE consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' . 'WHERE consumer_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); @@ -150,39 +150,39 @@ public function deleteContext($context) $id = $context->getRecordId(); // Delete any outstanding share keys for resource links for this context - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "WHERE ({$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any users in resource links for this context - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))'; + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' . + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "WHERE ({$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Update any resource links for which this consumer is acting as a primary resource link - $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'SET primary_resource_link_pk = null, share_approved = null ' . - "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' . - "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))'; + "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' . + "WHERE ({$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete any resource links for this consumer - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE context_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->execute(); // Delete context - $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . + $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' . 'WHERE context_pk = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT);