Save tool consumer object.

@param ToolConsumer $consumer Consumer object

@return boolean True if the tool consumer object was successfully saved
482795
public function saveToolConsumer($consumer)
    {

        $id = $consumer->getRecordId();
        $key = $consumer->getKey();
        $key256 = $this->getConsumerKey($key);
        if ($key === $key256) {
            $key = null;
        }
        $protected = ($consumer->protected) ? 1 : 0;
        $enabled = ($consumer->enabled)? 1 : 0;
        $profile = (!empty($consumer->profile)) ? json_encode($consumer->profile) : null;
        $settingsValue = serialize($consumer->getSettings());
        $time = time();
        $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
        $from = null;
        if (!is_null($consumer->enableFrom)) {
            $from = date("{$this->dateFormat} {$this->timeFormat}", $consumer->enableFrom);
        }
        $until = null;
        if (!is_null($consumer->enableUntil)) {
            $until = date("{$this->dateFormat} {$this->timeFormat}", $consumer->enableUntil);
        }
        $last = null;
        if (!is_null($consumer->lastAccess)) {
            $last = date($this->dateFormat, $consumer->lastAccess);
        }
        if (empty($id)) {
            $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::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, ' .
                   ':protected, :enabled, :enable_from, :enable_until, :last_access, :created, :updated)';
            $query = $this->db->prepare($sql);
            $query->bindValue('key256', $key256, PDO::PARAM_STR);
            $query->bindValue('key', $key, PDO::PARAM_STR);
            $query->bindValue('name', $consumer->name, PDO::PARAM_STR);
            $query->bindValue('secret', $consumer->secret, PDO::PARAM_STR);
            $query->bindValue('lti_version', $consumer->ltiVersion, PDO::PARAM_STR);
            $query->bindValue('consumer_name', $consumer->consumerName, PDO::PARAM_STR);
            $query->bindValue('consumer_version', $consumer->consumerVersion, PDO::PARAM_STR);
            $query->bindValue('consumer_guid', $consumer->consumerGuid, PDO::PARAM_STR);
            $query->bindValue('profile', $profile, PDO::PARAM_STR);
            $query->bindValue('tool_proxy', $consumer->toolProxy, PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('protected', $protected, PDO::PARAM_INT);
            $query->bindValue('enabled', $enabled, PDO::PARAM_INT);
            $query->bindValue('enable_from', $from, PDO::PARAM_STR);
            $query->bindValue('enable_until', $until, PDO::PARAM_STR);
            $query->bindValue('last_access', $last, PDO::PARAM_STR);
            $query->bindValue('created', $now, PDO::PARAM_STR);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
        } else {
            $sql = 'UPDATE ' . $this->dbTableNamePrefix . DataConnector::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, ' .
                   'protected = :protected, enabled = :enabled, enable_from = :enable_from, enable_until = :enable_until, last_access = :last_access, updated = :updated ' .
                   'WHERE consumer_pk = :id';
            $query = $this->db->prepare($sql);
            $query->bindValue('key256', $key256, PDO::PARAM_STR);
            $query->bindValue('key', $key, PDO::PARAM_STR);
            $query->bindValue('name', $consumer->name, PDO::PARAM_STR);
            $query->bindValue('secret', $consumer->secret, PDO::PARAM_STR);
            $query->bindValue('lti_version', $consumer->ltiVersion, PDO::PARAM_STR);
            $query->bindValue('consumer_name', $consumer->consumerName, PDO::PARAM_STR);
            $query->bindValue('consumer_version', $consumer->consumerVersion, PDO::PARAM_STR);
            $query->bindValue('consumer_guid', $consumer->consumerGuid, PDO::PARAM_STR);
            $query->bindValue('profile', $profile, PDO::PARAM_STR);
            $query->bindValue('tool_proxy', $consumer->toolProxy, PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('protected', $protected, PDO::PARAM_INT);
            $query->bindValue('enabled', $enabled, PDO::PARAM_INT);
            $query->bindValue('enable_from', $from, PDO::PARAM_STR);
            $query->bindValue('enable_until', $until, PDO::PARAM_STR);
            $query->bindValue('last_access', $last, PDO::PARAM_STR);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
            $query->bindValue('id', $id, PDO::PARAM_INT);
        }
        $ok = $query->execute();
        if ($ok) {
            if (empty($id)) {
                $consumer->setRecordId(intval($this->db->lastInsertId()));
                $consumer->created = $time;
            }
            $consumer->updated = $time;
        }

        return $ok;

    }
1302770
protected function setParseHeaderValue(AbstractConsumer $consumer)
    {
        parent::setParseHeaderValue($consumer);
        foreach ($this->parts as $part) {
            if ($part instanceof CommentPart) {
                $this->comments[] = $part->getComment();
            } elseif ($part instanceof DatePart) {
                $this->date = $part->getDateTime();
            }
        }
    }
320906
public function get_resourcelink_from_consumer(ToolConsumer $consumer) {
        global $DB;

        $resourcelink = null;
        if ($resourcelinkrecord = $DB->get_record($this->resourcelinktable, ['consumerid' => $consumer->getRecordId()],
            'ltiresourcelinkkey')) {
            $resourcelink = ResourceLink::fromConsumer($consumer, $resourcelinkrecord->ltiresourcelinkkey);
        }

        return $resourcelink;
    }
810614
public void unregisterConsumer( LocalMessageConsumer consumer )
    {
    	consumersLock.writeLock().lock();
    	try
    	{
    		localConsumers.remove(consumer);
    	}
    	finally
    	{
    		consumersLock.writeLock().unlock();
    	}
    }
513180
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';
        $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 ' .
               'WHERE 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 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 ' .
               'WHERE 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 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 ' .
               'WHERE 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 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 ' .
               '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 ' .
               'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
               'WHERE 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 . ' 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 ' .
               'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
               'WHERE 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 rl ' .
               "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
               'WHERE rl.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 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 ' .
               'WHERE 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 c ' .
               "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ' .
               'WHERE c.consumer_pk = :id';
        $query = $this->db->prepare($sql);
        $query->bindValue('id', $id, PDO::PARAM_INT);
        $query->execute();

// Delete consumer
        $sql = 'DELETE c ' .
               "FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' c ' .
               'WHERE c.consumer_pk = :id';
        $query = $this->db->prepare($sql);
        $query->bindValue('id', $id, PDO::PARAM_INT);
        $ok = $query->execute();

        if ($ok) {
            $consumer->initialize();
        }

        return $ok;

    }
1329979
protected final void registerConsumer( AbstractMessageConsumer consumer )
    {
        if (consumersMap.put(consumer.getId(),consumer) != null)
        	throw new IllegalArgumentException("Consumer "+consumer.getId()+" already exists");
    }
1319161
protected function fetch_members_from_consumer(ToolConsumer $consumer) {
        $dataconnector = $this->dataconnector;

        // Get membership URL template from consumer profile data.
        $defaultmembershipsurl = null;
        if (isset($consumer->profile->service_offered)) {
            $servicesoffered = $consumer->profile->service_offered;
            foreach ($servicesoffered as $service) {
                if (isset($service->{'@id'}) && strpos($service->{'@id'}, 'tcp:ToolProxyBindingMemberships') !== false &&
                    isset($service->endpoint)) {
                    $defaultmembershipsurl = $service->endpoint;
                    if (isset($consumer->profile->product_instance->product_info->product_family->vendor->code)) {
                        $vendorcode = $consumer->profile->product_instance->product_info->product_family->vendor->code;
                        $defaultmembershipsurl = str_replace('{vendor_code}', $vendorcode, $defaultmembershipsurl);
                    }
                    $defaultmembershipsurl = str_replace('{product_code}', $consumer->getKey(), $defaultmembershipsurl);
                    break;
                }
            }
        }

        $members = false;

        // Fetch the resource link linked to the consumer.
        $resourcelink = $dataconnector->get_resourcelink_from_consumer($consumer);
        if ($resourcelink !== null) {
            // Try to perform a membership service request using this resource link.
            $members = $this->do_resourcelink_membership_request($resourcelink);
        }

        // If membership service can't be performed through resource link, fallback through context memberships.
        if ($members === false) {
            // Fetch context records that are mapped to this ToolConsumer.
            $contexts = $dataconnector->get_contexts_from_consumer($consumer);

            // Perform membership service request for each of these contexts.
            foreach ($contexts as $context) {
                $contextmembership = $this->do_context_membership_request($context, $resourcelink, $defaultmembershipsurl);
                if ($contextmembership) {
                    // Add $contextmembership contents to $members array.
                    if (is_array($members)) {
                        $members = array_merge($members, $contextmembership);
                    } else {
                        $members = $contextmembership;
                    }
                }
            }
        }

        return $members;
    }
997074
public function loadToolConsumer($consumer)
    {

        $ok = false;
        if (!empty($consumer->getRecordId())) {
            $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 . ' ' .
                           "WHERE consumer_pk = %d",
                           $consumer->getRecordId());
        } else {
            $key256 = DataConnector::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 . ' ' .
                           "WHERE consumer_key256 = %s",
                           DataConnector::quoted($key256));
        }
        $rsConsumer = mysql_query($sql);
        if ($rsConsumer) {
            while ($row = mysql_fetch_object($rsConsumer)) {
                if (empty($key256) || empty($row->consumer_key) || ($consumer->getKey() === $row->consumer_key)) {
                    $consumer->setRecordId(intval($row->consumer_pk));
                    $consumer->name = $row->name;
                    $consumer->setkey(empty($row->consumer_key) ? $row->consumer_key256 : $row->consumer_key);
                    $consumer->secret = $row->secret;
                    $consumer->ltiVersion = $row->lti_version;
                    $consumer->consumerName = $row->consumer_name;
                    $consumer->consumerVersion = $row->consumer_version;
                    $consumer->consumerGuid = $row->consumer_guid;
                    $consumer->profile = json_decode($row->profile);
                    $consumer->toolProxy = $row->tool_proxy;
                    $settings = unserialize($row->settings);
                    if (!is_array($settings)) {
                        $settings = array();
                    }
                    $consumer->setSettings($settings);
                    $consumer->protected = (intval($row->protected) === 1);
                    $consumer->enabled = (intval($row->enabled) === 1);
                    $consumer->enableFrom = null;
                    if (!is_null($row->enable_from)) {
                        $consumer->enableFrom = strtotime($row->enable_from);
                    }
                    $consumer->enableUntil = null;
                    if (!is_null($row->enable_until)) {
                        $consumer->enableUntil = strtotime($row->enable_until);
                    }
                    $consumer->lastAccess = null;
                    if (!is_null($row->last_access)) {
                        $consumer->lastAccess = strtotime($row->last_access);
                    }
                    $consumer->created = strtotime($row->created);
                    $consumer->updated = strtotime($row->updated);
                    $ok = true;
                    break;
                }
            }
            mysql_free_result($rsConsumer);
        }

        return $ok;

    }
1117063
public function save(CacheItemInterface $item)
    {
        $metadata = $item->getMetadata();
        $metadata[ 'data' ] = $item->get();
        $metadata = serialize($metadata);

        $path = $this->path . $this->prefixKey . $item->getKey() . '.cache';

        if ( ! $fp = @fopen($path, 'wb')) {
            return false;
        }

        flock($fp, LOCK_EX);

        for ($result = $written = 0, $length = strlen($metadata); $written < $length; $written += $result) {
            if (($result = fwrite($fp, substr($metadata, $written))) === false) {
                break;
            }
        }

        flock($fp, LOCK_UN);
        fclose($fp);

        return (bool)is_int($result);
    }
850520
public function getConsumer()
    {

        if (is_null($this->consumer)) {
            $this->consumer = ToolConsumer::fromRecordId($this->consumerId, $this->getDataConnector());
        }

        return $this->consumer;

    }
935428
void removeConsumerSession(ConsumerSessionImpl consumer)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "removeConsumerSession", consumer);

        synchronized (_consumers)
        {
            _consumers.remove(consumer);
        }

        _messageProcessor.removeConsumer(consumer);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "removeConsumerSession");
    }
470006
public function save($trace = false)
    {
        $retval = parent::save($trace);

        $this->nb_attachment_list->iterate(
            function ($key, CNabuIContactProspectAttachment $nb_attachment) use ($retval) {
                $retval |= $nb_attachment->save();
                return true;
            }
        );

        return $retval;
    }
725868
protected function save(UserInterface $user)
    {
        try
        {
            $entityManager = $this->getEntityManager();
            $entityManager->persist($user);
            $entityManager->flush();

            return $user;
        }
        catch (\Exception $e)
        {
            return false;
        }
    }
1109212
public function loadToolConsumer($consumer) {
        global $DB;

        $id = $consumer->getRecordId();

        if (!empty($id)) {
            $result = $DB->get_record($this->consumertable, ['id' => $id]);
        } else {
            $key256 = DataConnector::getConsumerKey($consumer->getKey());
            $result = $DB->get_record($this->consumertable, ['consumerkey256' => $key256]);
        }

        if ($result) {
            if (empty($key256) || empty($result->consumerkey) || ($consumer->getKey() === $result->consumerkey)) {
                $this->build_tool_consumer_object($result, $consumer);
                return true;
            }
        }

        return false;
    }
817211
public function createConsumer(Destination $destination): Consumer
    {
        InvalidDestinationException::assertDestinationInstanceOf($destination, RdKafkaTopic::class);

        $this->kafkaConsumers[] = $kafkaConsumer = new KafkaConsumer($this->getConf());

        $consumer = new RdKafkaConsumer(
            $kafkaConsumer,
            $this,
            $destination,
            $this->getSerializer()
        );

        if (isset($this->config['commit_async'])) {
            $consumer->setCommitAsync($this->config['commit_async']);
        }

        return $consumer;
    }
409721
public Link<S, T> to(Consumer<S, T> consumer) {
		this.consumer = consumer;
		return this;
	}
479018
public function saveDeferred(CacheItemInterface $item)
    {
        $key = spl_object_id($item);

        if ( ! array_key_exists($key, $this->deferred)) {
            $this->deferred[] = $item;

            return true;
        }

        return false;
    }