Save 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 saved
487342
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 . ' ' .
               '(share_key_id, resource_link_pk, auto_approve, expires) ' .
               'VALUES (:id, :prlid, :approve, :expires)';
        $query = $this->db->prepare($sql);
        $query->bindValue('id', $id, PDO::PARAM_STR);
        $query->bindValue('prlid', $shareKey->resourceLinkId, PDO::PARAM_INT);
        $query->bindValue('approve', $shareKey->autoApprove, PDO::PARAM_INT);
        $query->bindValue('expires', $expires, PDO::PARAM_STR);
        $ok = $query->execute();

        return $ok;

    }
886484
public function addLinksArray($key, LinksArray $linksArray) {
		Validator::checkMemberName($key);
		
		if (isset($this->links[$key])) {
			throw new DuplicateException('link with key "'.$key.'" already set');
		}
		
		$this->links[$key] = $linksArray;
	}
1311043
public function save($key, $value)
    {
        list($namespace, $group, $item) = $this->parseKey($key);
        $collection = $this->getCollection($group, $namespace);
        unset($this->items[$collection]);

        if ($this->saver->save($item, $value, $this->environment, $group, $namespace)) {
            $this->load($group, $namespace, $this->getCollection($group, $namespace));

            return true;
        }

        return false;
    }
391807
public function loadResourceLinkShareKey($shareKey)
    {

        $ok = false;

// 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}'";
        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 . ' ' .
               "WHERE share_key_id = '{$id}'";
        $rsShareKey = mysql_query($sql);
        if ($rsShareKey) {
            $row = mysql_fetch_object($rsShareKey);
            if ($row && (intval($row->resource_link_pk) === $shareKey->resourceLinkId)) {
                $shareKey->autoApprove = (intval($row->auto_approve) === 1);
                $shareKey->expires = strtotime($row->expires);
                $ok = true;
            }
        }

        return $ok;

    }
385005
public function saveResourceLink($resourceLink) {

        $time = time();
        $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
        $settingsValue = serialize($resourceLink->getSettings());
        if (!empty($resourceLink->getContext())) {
            $consumerId = null;
            $contextId = strval($resourceLink->getContext()->getRecordId());
        } else if (!empty($resourceLink->getContextId())) {
            $consumerId = null;
            $contextId = strval($resourceLink->getContextId());
        } else {
            $consumerId = strval($resourceLink->getConsumer()->getRecordId());
            $contextId = null;
        }
        if (empty($resourceLink->primaryResourceLinkId)) {
            $primaryResourceLinkId = null;
        } else {
            $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
        }
        $id = $resourceLink->getRecordId();
        if (empty($id)) {
            $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::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);
            $query->bindValue('cid', $consumerId, PDO::PARAM_INT);
            $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
            $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
            $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
            $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 ' .
                   '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)';
            $query = $this->db->prepare($sql);
            $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
            $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
            $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
            $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 ' .
                   '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)';
            $query = $this->db->prepare($sql);
            $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
            $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
            $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
            $query->bindValue('cid', $consumerId, PDO::PARAM_INT);
            $query->bindValue('id', $id, PDO::PARAM_INT);
        }
        $ok = $query->execute();
        if ($ok) {
            if (empty($id)) {
                $resourceLink->setRecordId(intval($this->db->lastInsertId()));
                $resourceLink->created = $time;
            }
            $resourceLink->updated = $time;
        }

        return $ok;

    }
364276
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;

    }
129252
protected function saveRelationsAfterHasMany($key)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($this);
        $relation = $class::getRelations()[$key];
        $column = $class::getRelationLinkName($relation);

        /** @var \T4\Core\Collection $oldSubModelsSet */
        $oldSubModelsSet = $this->getRelationLazy($key);
        /** @var \T4\Core\Collection $newSubModelsSet */
        $newSubModelsSet = $this->{$key};

        $toDeletePks =
            array_diff(
                $oldSubModelsSet->collect($relation['model']::PK),
                $newSubModelsSet->collect($relation['model']::PK)
            );

        foreach ($toDeletePks as $toDeletePk) {
            /** @var \T4\Orm\Model $subModel */
            $subModel = $oldSubModelsSet->findByAttributes([$relation['model']::PK => $toDeletePk]);
            $subModel->{$column} = null;
            $subModel->save();
        }

        foreach ( $newSubModelsSet ?: [] as $subModel ) {
            /** @var \T4\Orm\Model $subModel */
            $subModel->{$column} = $this->getPk();
            $subModel->save();
        }
    }
859301
public function addLinkString($key, $href) {
		Validator::checkMemberName($key);
		
		if (isset($this->links[$key])) {
			throw new DuplicateException('link with key "'.$key.'" already set');
		}
		
		$this->links[$key] = $href;
	}
943915
protected function saveToCache($cacheKey, $content)
    {
        // Create or update the index list containing all cache keys for a given image and filter pairing.
        $indexKey = $this->generateIndexKey($cacheKey);
        if ($this->cache->contains($indexKey)) {
            $index = (array) $this->cache->fetch($indexKey);

            if (!\in_array($cacheKey, $index, true)) {
                $index[] = $cacheKey;
            }
        } else {
            $index = [$cacheKey];
        }

        /*
         * Only save the content, if the index has been updated successfully.
         * This is required to have a (hopefully) synchron state between cache and backend.
         *
         * "Hopefully" because there are caches (like Memcache) which will remove keys by themselves.
         */
        if ($this->cache->save($indexKey, $index)) {
            return $this->cache->save($cacheKey, $content);
        }

        return false;
    }
722904
public function save()
    {

        $ok = $this->getDataConnector()->saveResourceLink($this);
        if ($ok) {
            $this->settingsChanged = false;
        }

        return $ok;

    }
1254938
public function ownedBy(Model $related = null, ?string $key = null): bool
    {
        if (\is_null($related)) {
            return false;
        }

        if (\is_null($key)) {
            $key = $related->getForeignKey();
        }

        return $this->getAttribute($key) == $related->getKey();
    }
868784
public function saveResourceLink($resourceLink) {

        if (is_null($resourceLink->shareApproved)) {
            $approved = 'NULL';
        } else if ($resourceLink->shareApproved) {
            $approved = '1';
        } else {
            $approved = '0';
        }
        if (empty($resourceLink->primaryResourceLinkId)) {
            $primaryResourceLinkId = 'NULL';
        } else {
            $primaryResourceLinkId = strval($resourceLink->primaryResourceLinkId);
        }
        $time = time();
        $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
        $settingsValue = serialize($resourceLink->getSettings());
        if (!empty($resourceLink->getContext())) {
            $consumerId = 'NULL';
            $contextId = strval($resourceLink->getContext()->getRecordId());
        } else if (!empty($resourceLink->getContextId())) {
            $consumerId = 'NULL';
            $contextId = strval($resourceLink->getContextId());
        } else {
            $consumerId = strval($resourceLink->getConsumer()->getRecordId());
            $contextId = 'NULL';
        }
        $id = $resourceLink->getRecordId();
        if (empty($id)) {
            $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::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));
        } else if ($contextId !== 'NULL') {
            $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::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),
                           $contextId, $id);
        } else {
            $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::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),
                           $consumerId, $id);
        }
        $ok = mysql_query($sql);
        if ($ok) {
            if (empty($id)) {
                $resourceLink->setRecordId(mysql_insert_id());
                $resourceLink->created = $time;
            }
            $resourceLink->updated = $time;
        }

        return $ok;

    }
529574
public function save()
    {
        if (!empty($this->ltiResultSourcedId) && !is_null($this->resourceLink)) {
            $ok = $this->resourceLink->getConsumer()->getStorage()->userSave($this);
        } else {
            $ok = true;
        }

        return $ok;
    }
409134
public function loadResourceLink($resourceLink)
    {

        $now = time();
        $resourceLink->created = $now;
        $resourceLink->updated = $now;

        return true;

    }
662973
function fileLinkCopy( $srcPath, $dstPath, $symLink )
    {
        $srcPath = self::cleanPath( $srcPath );
        $dstPath = self::cleanPath( $dstPath );
        eZDebugSetting::writeDebug( 'kernel-clustering', "dfs::fileLinkCopy( '$srcPath', '$dstPath' )" );

        self::$dbbackend->_linkCopy( $srcPath, $dstPath );
    }
1211143
public static base_responses link(nitro_service client, sslcertkey resources[]) throws Exception {
		base_responses result = null;
		if (resources != null && resources.length > 0) {
			sslcertkey linkresources[] = new sslcertkey[resources.length];
			for (int i=0;i<resources.length;i++){
				linkresources[i] = new sslcertkey();
				linkresources[i].certkey = resources[i].certkey;
				linkresources[i].linkcertkeyname = resources[i].linkcertkeyname;
			}
			result = perform_operation_bulk_request(client, linkresources,"link");
		}
		return result;
	}
962373
public function save($bOnDuplicateKeyUpdate = false)
    {
        /**
         * Trigger on an entity to initialize it before the save
         */
        if (method_exists(get_called_class(), 'beforeSave')) { static::beforeSave(); }

        $mPrimaryKeyName = $this->_mPrimaryKeyName;

        if ($bOnDuplicateKeyUpdate === false) { $bInsertMode = false; }
        else { $bInsertMode = true; }

        if ($mPrimaryKeyName === false) {

            throw new \Exception('['.__FILE__.' (l.'.__LINE__.'] no primary key on this table!');
        }
        else if (is_string($mPrimaryKeyName)) {

            $sMethodPrimaryKey = 'get_'.$this->_mPrimaryKeyNameWithoutMapping;
            $aPrimaryKey = array($mPrimaryKeyName => $this->$sMethodPrimaryKey());

            if ($this->$sMethodPrimaryKey() < 1) { $bInsertMode = true; }
        }
        else {

            $aPrimaryKey = array();

            $oOrm = new Orm;

            $iResults = $oOrm->select(array('*'))
                ->from(preg_replace('/^.*\\\\([a-zA-Z0-9_]+)$/', '$1', get_called_class()));

            $oWhere = new Where;

            foreach($mPrimaryKeyName as $sKey => $sPrimaryKey) {

                $sMethodPrimaryKey = 'get_'.$this->_mPrimaryKeyNameWithoutMapping[$sKey];
                $aPrimaryKey[$sPrimaryKey] = $this->$sMethodPrimaryKey();


                $oWhere->andWhereEqual($sPrimaryKey, $aPrimaryKey[$sPrimaryKey]);
            }

            $aResults = $oOrm->where($oWhere)
                ->load();

            if (count($aResults) < 1) { $bInsertMode = true; }
        }

        $aEntityTmp = get_object_vars(LibEntity::getRealEntity($this));
        $aEntity = array();

        foreach ($aEntityTmp as $sKey => $mField) {

            if ($mField !== null && !is_object($mField)) {

                $aEntity[$sKey] = $mField;
            }
        }

        /**
         * check if the virtual foreign key in this model is respected
         */
        if (count($this->_aForeignKey) > 0) {

            foreach ($this->_aForeignKey as $sName => $aForeignKey) {

                if ($aForeignKey['has_one'] == 1) {

                    $sMethodPrimaryKey = 'get_'.$aForeignKey['foreign_key'];
                    $mFIeld = $this->$sMethodPrimaryKey();

                    if ($mFIeld) {

                        $oOrm = new Orm;

                        $iResults = $oOrm->select(array('*'))
                            ->from($aForeignKey['entity_join_name']);

                        $oWhere = new Where;

                        $oWhere->whereEqual($aForeignKey['primary_key_name'], $mFIeld);

                        $aResults = $oOrm->where($oWhere)
                            ->load();

                        if (count($aResults) < 1) {

                            if ($aForeignKey['foreign_key_options']['message']) {

                                throw new \Exception($aForeignKey['foreign_key_options']['message']);
                            }
                            else {

                                throw new \Exception('Foreign Key not respected!');
                            }
                        }
                    }
                }
            }
        }

        /**
         * check if the virtual foreign key in the others models are respected
         */
        $oReflectionClass  = new \ReflectionClass(get_called_class());
        $oReflectionProperties = $oReflectionClass->getProperties();

        foreach($oReflectionProperties as $mKey => $aOne) {

            $sCommentPhpDoc = $aOne->getDocComment();

            if (strstr($sCommentPhpDoc, '@OneToMany')) {

                $sClassName = $aOne->class;
                $oClass = new $sClassName;

                if (count($oClass->getForeignKey()) > 0) {

                    foreach ($oClass->getForeignKey() as $sName => $aForeignKey) {

                        if ($aForeignKey['has_many'] == 1) {

                            $sMethodPrimaryKey = 'get_'.$aForeignKey['foreign_key'];
                            $mFIeld = $this->$sMethodPrimaryKey();

                            if ($mFIeld) {

                                $oOrm = new Orm;

                                $iResults = $oOrm->select(array('*'))
                                    ->from($aForeignKey['entity_join_name']);

                                $oWhere = new Where;

                                $oWhere->whereEqual($aForeignKey['primary_key_name'], $mFIeld);

                                $aResults = $oOrm->where($oWhere)
                                    ->load();

                                if (count($aResults) < 1) {

                                    if ($aForeignKey['foreign_key_options']['message']) {

                                        throw new \Exception($aForeignKey['foreign_key_options']['message']);
                                    }
                                    else {

                                        throw new \Exception('Foreign Key not respected!');
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        $oOrm = new Orm;

        if ($bInsertMode === true) {

            $oOrm->insert(preg_replace('/^.*\\\\([a-zA-Z0-9_]+)$/', '$1', get_called_class()))
                ->values($aEntity);

            if ($bOnDuplicateKeyUpdate === true) {

                $oOrm->onDuplicateKeyUpdate($aEntity);
            }

            $iResults = $oOrm->save();
        }
        else {

            $iResults = $oOrm->update(preg_replace('/^.*\\\\([a-zA-Z0-9_]+)$/', '$1', get_called_class()))
                ->set($aEntity)
                ->where($aPrimaryKey)
                ->save();
        }

        if (is_string(LibEntity::getPrimaryKeyName($this))) {
            $methodName = 'set_'.LibEntity::getPrimaryKeyName($this);
            $this->$methodName($iResults);
        }

        return $iResults;
    }