Exemplo n.º 1
0
    /**
     * @param $key
     * @param $value
     * @param $propertyId
     * @param $updateTime
     * @param $rowStatusId
     * @param $cellLanguage
     * @param $cellType
     * @param $schemaId
     *
     * @return array $results
     * @throws \PropelException
     */
    private function SetPropertyElement(
        $key,
        $value,
        $propertyId,
        $updateTime,
        $rowStatusId,
        $cellLanguage,
        $cellType
    ) {
        $profilePropertyId = $this->prolog['columns'][$key]['id'];
        if (is_array($profilePropertyId)) {
            $profilePropertyId = $profilePropertyId[0];
        }

        //check to see if the property already exists
        //note that this also checks the object value as well, so there's no way to update or delete an existing triple
        //the sheet would have to contain the identifier for the triple

        //actually there is. We look for exact matches and skip the update of an exact match,
        //but then we look at just the old properties that are left -- the ones where the property matches but the object doesn't
        //and we update those. If we have any properties left after that, we add them as new.
        //We need to add an instruction to the spreadsheet to treat an empty property cell as a skip or a delete
        //and if an empty cell means delete, then we delete those

        //get the language for this thing
        //if there's a prolog set for the language for this column, use it
        //use the default for the import (already set above)
        //fall back to the default language of the vocabulary

        //get the fqn if using curies
        if ($cellType and $this->useCuries) {
            $value = $this->getFqn($value);
        }

        $StatementCounter['status'] = 'skipped';

        /** @var \SchemaPropertyElement[] $element */
        $element = \SchemaPropertyElementPeer::lookupElement($propertyId, $profilePropertyId, $value, $cellLanguage);

        if ($element) {
            if (1 === count($element)) {
                $element = $element[0];
                //make sure we handle the special case of subproperty and subclass
                if (empty( $value ) && $element->getIsSchemaProperty() && in_array($element->getProfilePropertyId(),
                                                                                   [ 6, 9 ])
                ) {
                    return $StatementCounter;
                }
            } else {
                //it's ambiguous and we stop processing, logging an error to be dealt with later
                $error['Message']           = "Ambiguous update";
                $error['PropertyId']        = $propertyId;
                $error['ProfilePropertyId'] = $profilePropertyId;
                $error['UpdateValue']       = $value;

                $this->results['errors'][] = $error;
            }
        }

        //create a new propertyelement for each unmatched column
        //we didn't find an existing element, make a new one
        if ( ! $element && ! empty( $value )) {
            $element = new \SchemaPropertyElement;
            $element->setCreatedUserId($this->userId);
            $element->setCreatedAt($updateTime);
            $element->setProfilePropertyId($profilePropertyId);
            $element->setSchemaPropertyId($propertyId);
            $StatementCounter['status'] = 'created';
        }

        if ( ! $element) {
            return $StatementCounter;
        }

        if (( $value != $element->getObject() ) || ( $cellLanguage != $element->getLanguage() )) {
            /**
             * @todo We need a check here for objectproperties and handle differently
             *       if it's a URI, and it uses namespaces, and we have the namespace, do the substitution
             **/
            if ( ! $cellType and $cellLanguage) {
                if ($cellLanguage != $element->getLanguage()) {
                    $element->setLanguage($cellLanguage);
                }
            }
        }
        if ($value != $element->getObject()) {
            if ( ! empty( $value )) {
                $element->setObject($value);
            } else {
                $element->setDeletedAt($updateTime);
            }
        }

        if ($element->isNew() or $element->isModified()) {
            $element->setUpdatedUserId($this->userId);
            $element->setUpdatedAt($updateTime);
            $element->setStatusId($rowStatusId);
            $element->importId = $this->importId;
            $element->save();

            if ($StatementCounter['status'] != 'created') {
                $StatementCounter['status'] = 'modified';
            }

            if (is_array($element->getProfilePropertyId())) {
                $profilePropertyId = $element->getProfilePropertyId()[0];
            } else {
                $profilePropertyId = $element->getProfilePropertyId();
            }
            /** @var \ProfileProperty $profileProperty */
            $profileProperty                = $this->profileProperties[$profilePropertyId];
            $StatementCounter['column']     = $key;
            $StatementCounter['id']         = $element->getId();
            $StatementCounter['propertyId'] = $element->getProfilePropertyId();
            $StatementCounter['object']     = $element->getObject();
            $StatementCounter['type']       = $cellType;
            $StatementCounter['language']   = $cellLanguage;
        }

        unset( $element );

        return $StatementCounter;
    }
 /**
  * Stores the object in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      Connection $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave($con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUser !== null) {
             if ($this->aUser->isModified()) {
                 $affectedRows += $this->aUser->save($con);
             }
             $this->setUser($this->aUser);
         }
         if ($this->aSchemaPropertyElement !== null) {
             if ($this->aSchemaPropertyElement->isModified()) {
                 $affectedRows += $this->aSchemaPropertyElement->save($con);
             }
             $this->setSchemaPropertyElement($this->aSchemaPropertyElement);
         }
         if ($this->aSchemaPropertyRelatedBySchemaPropertyId !== null) {
             if ($this->aSchemaPropertyRelatedBySchemaPropertyId->isModified()) {
                 $affectedRows += $this->aSchemaPropertyRelatedBySchemaPropertyId->save($con);
             }
             $this->setSchemaPropertyRelatedBySchemaPropertyId($this->aSchemaPropertyRelatedBySchemaPropertyId);
         }
         if ($this->aSchema !== null) {
             if ($this->aSchema->isModified()) {
                 $affectedRows += $this->aSchema->save($con);
             }
             $this->setSchema($this->aSchema);
         }
         if ($this->aProfileProperty !== null) {
             if ($this->aProfileProperty->isModified()) {
                 $affectedRows += $this->aProfileProperty->save($con);
             }
             $this->setProfileProperty($this->aProfileProperty);
         }
         if ($this->aSchemaPropertyRelatedByRelatedSchemaPropertyId !== null) {
             if ($this->aSchemaPropertyRelatedByRelatedSchemaPropertyId->isModified()) {
                 $affectedRows += $this->aSchemaPropertyRelatedByRelatedSchemaPropertyId->save($con);
             }
             $this->setSchemaPropertyRelatedByRelatedSchemaPropertyId($this->aSchemaPropertyRelatedByRelatedSchemaPropertyId);
         }
         if ($this->aStatus !== null) {
             if ($this->aStatus->isModified()) {
                 $affectedRows += $this->aStatus->save($con);
             }
             $this->setStatus($this->aStatus);
         }
         if ($this->aFileImportHistory !== null) {
             if ($this->aFileImportHistory->isModified()) {
                 $affectedRows += $this->aFileImportHistory->save($con);
             }
             $this->setFileImportHistory($this->aFileImportHistory);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = SchemaPropertyElementHistoryPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += SchemaPropertyElementHistoryPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemplo n.º 3
0
 /**
  * Stores the object in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      Connection $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave($con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUserRelatedByCreatedUserId !== null) {
             if ($this->aUserRelatedByCreatedUserId->isModified()) {
                 $affectedRows += $this->aUserRelatedByCreatedUserId->save($con);
             }
             $this->setUserRelatedByCreatedUserId($this->aUserRelatedByCreatedUserId);
         }
         if ($this->aUserRelatedByDeletedUserId !== null) {
             if ($this->aUserRelatedByDeletedUserId->isModified()) {
                 $affectedRows += $this->aUserRelatedByDeletedUserId->save($con);
             }
             $this->setUserRelatedByDeletedUserId($this->aUserRelatedByDeletedUserId);
         }
         if ($this->aSchema !== null) {
             if ($this->aSchema->isModified()) {
                 $affectedRows += $this->aSchema->save($con);
             }
             $this->setSchema($this->aSchema);
         }
         if ($this->aSchemaProperty !== null) {
             if ($this->aSchemaProperty->isModified()) {
                 $affectedRows += $this->aSchemaProperty->save($con);
             }
             $this->setSchemaProperty($this->aSchemaProperty);
         }
         if ($this->aSchemaPropertyElement !== null) {
             if ($this->aSchemaPropertyElement->isModified()) {
                 $affectedRows += $this->aSchemaPropertyElement->save($con);
             }
             $this->setSchemaPropertyElement($this->aSchemaPropertyElement);
         }
         if ($this->aVocabulary !== null) {
             if ($this->aVocabulary->isModified()) {
                 $affectedRows += $this->aVocabulary->save($con);
             }
             $this->setVocabulary($this->aVocabulary);
         }
         if ($this->aConcept !== null) {
             if ($this->aConcept->isModified()) {
                 $affectedRows += $this->aConcept->save($con);
             }
             $this->setConcept($this->aConcept);
         }
         if ($this->aConceptProperty !== null) {
             if ($this->aConceptProperty->isModified()) {
                 $affectedRows += $this->aConceptProperty->save($con);
             }
             $this->setConceptProperty($this->aConceptProperty);
         }
         if ($this->aDiscussRelatedByRootId !== null) {
             if ($this->aDiscussRelatedByRootId->isModified()) {
                 $affectedRows += $this->aDiscussRelatedByRootId->save($con);
             }
             $this->setDiscussRelatedByRootId($this->aDiscussRelatedByRootId);
         }
         if ($this->aDiscussRelatedByParentId !== null) {
             if ($this->aDiscussRelatedByParentId->isModified()) {
                 $affectedRows += $this->aDiscussRelatedByParentId->save($con);
             }
             $this->setDiscussRelatedByParentId($this->aDiscussRelatedByParentId);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = DiscussPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += DiscussPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collDiscusssRelatedByRootId !== null) {
             foreach ($this->collDiscusssRelatedByRootId as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collDiscusssRelatedByParentId !== null) {
             foreach ($this->collDiscusssRelatedByParentId as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }