/**
  * Delete resource link share key object.
  *
  * @param ResourceLinkShareKey $shareKey Resource link share key object
  *
  * @return boolean True if the resource link share key object was successfully deleted
  */
 public function deleteResourceLinkShareKey($shareKey)
 {
     $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . " WHERE share_key_id = '{$shareKey->getId()}'";
     $ok = mysql_query($sql);
     if ($ok) {
         $shareKey->initialize();
     }
     return $ok;
 }
Exemple #2
0
 /**
  * Test for data_connector::deleteResourceLinkShareKey().
  */
 public function test_delete_resource_link_share_key()
 {
     $dc = new data_connector();
     $consumer = new ToolConsumer(null, $dc);
     $consumer->name = 'TestName';
     $consumer->setKey('TestKey');
     $consumer->secret = 'TestSecret';
     $consumer->save();
     $resourcelink = ResourceLink::fromConsumer($consumer, 'testresourcelinkid');
     $resourcelink->save();
     $sharekey = new ResourceLinkShareKey($resourcelink, 'testsharelinkid');
     $sharekey->save();
     $this->assertTrue($dc->deleteResourceLinkShareKey($sharekey));
     $controlsharekey = new ResourceLinkShareKey($resourcelink, 'testsharelinkid');
     $controlsharekey->initialise();
     $this->assertEquals($controlsharekey, $sharekey);
     // This should no longer be in the DB.
     $this->assertFalse($dc->loadResourceLinkShareKey($sharekey));
 }
Exemple #3
0
 /**
  * Delete resource link share key object.
  *
  * @param ResourceLinkShareKey $sharekey Resource link share key object
  * @return boolean True if the resource link share key object was successfully deleted
  */
 public function deleteResourceLinkShareKey($sharekey)
 {
     global $DB;
     $DB->delete_records($this->sharekeytable, ['sharekey' => $sharekey->getId()]);
     $sharekey->initialize();
     return true;
 }
Exemple #4
0
 /**
  * Check if a share arrangement is in place.
  *
  * @return boolean True if no error is reported
  */
 private function checkForShare()
 {
     $ok = true;
     $doSaveResourceLink = true;
     $id = $this->resourceLink->primaryResourceLinkId;
     $shareRequest = isset($_POST['custom_share_key']) && !empty($_POST['custom_share_key']);
     if ($shareRequest) {
         if (!$this->allowSharing) {
             $ok = false;
             $this->reason = 'Your sharing request has been refused because sharing is not being permitted.';
         } else {
             // Check if this is a new share key
             $shareKey = new ResourceLinkShareKey($this->resourceLink, $_POST['custom_share_key']);
             if (!is_null($shareKey->primaryConsumerKey) && !is_null($shareKey->primaryResourceLinkId)) {
                 // Update resource link with sharing primary resource link details
                 $key = $shareKey->primaryConsumerKey;
                 $id = $shareKey->primaryResourceLinkId;
                 $ok = $key !== $this->consumer->getKey() || $id != $this->resourceLink->getId();
                 if ($ok) {
                     $this->resourceLink->primaryConsumerKey = $key;
                     $this->resourceLink->primaryResourceLinkId = $id;
                     $this->resourceLink->shareApproved = $shareKey->autoApprove;
                     $ok = $this->resourceLink->save();
                     if ($ok) {
                         $doSaveResourceLink = false;
                         $this->user->getResourceLink()->primaryConsumerKey = $key;
                         $this->user->getResourceLink()->primaryResourceLinkId = $id;
                         $this->user->getResourceLink()->shareApproved = $shareKey->autoApprove;
                         $this->user->getResourceLink()->updated = time();
                         // Remove share key
                         $shareKey->delete();
                     } else {
                         $this->reason = 'An error occurred initialising your share arrangement.';
                     }
                 } else {
                     $this->reason = 'It is not possible to share your resource link with yourself.';
                 }
             }
             if ($ok) {
                 $ok = !is_null($key);
                 if (!$ok) {
                     $this->reason = 'You have requested to share a resource link but none is available.';
                 } else {
                     $ok = !is_null($this->user->getResourceLink()->shareApproved) && $this->user->getResourceLink()->shareApproved;
                     if (!$ok) {
                         $this->reason = 'Your share request is waiting to be approved.';
                     }
                 }
             }
         }
     } else {
         // Check no share is in place
         $ok = is_null($id);
         if (!$ok) {
             $this->reason = 'You have not requested to share a resource link but an arrangement is currently in place.';
         }
     }
     // Look up primary resource link
     if ($ok && !is_null($id)) {
         $consumer = new ToolConsumer($key, $this->dataConnector);
         $ok = !is_null($consumer->created);
         if ($ok) {
             $resourceLink = ResourceLink::fromConsumer($consumer, $id);
             $ok = !is_null($resourceLink->created);
         }
         if ($ok) {
             if ($doSaveResourceLink) {
                 $this->resourceLink->save();
             }
             $this->resourceLink = $resourceLink;
         } else {
             $this->reason = 'Unable to load resource link being shared.';
         }
     }
     return $ok;
 }
 /**
  * Delete resource link share key object.
  *
  * @param ResourceLinkShareKey $shareKey Resource link share key object
  *
  * @return boolean True if the resource link share key object was successfully deleted
  */
 public function deleteResourceLinkShareKey($shareKey)
 {
     $id = $shareKey->getId();
     $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::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();
     if ($ok) {
         $shareKey->initialize();
     }
     return $ok;
 }