예제 #1
0
 /**
  * Delete an mm-relation from a relation table
  *
  * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $relatedObject The related object
  * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject The parent object
  * @param string $parentPropertyName The name of the parent object's property where the related objects are stored in
  * @return bool
  */
 protected function deleteRelationFromRelationtable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $relatedObject, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName)
 {
     $dataMap = $this->dataMapper->getDataMap(get_class($parentObject));
     $columnMap = $dataMap->getColumnMap($parentPropertyName);
     $relationTableName = $columnMap->getRelationTableName();
     $relationMatchFields = array($columnMap->getParentKeyFieldName() => (int) $parentObject->getUid(), $columnMap->getChildKeyFieldName() => (int) $relatedObject->getUid());
     $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
     if (is_array($relationTableMatchFields)) {
         $relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields);
     }
     $res = $this->storageBackend->removeRow($relationTableName, $relationMatchFields, false);
     return $res;
 }
 /**
  * Since ExtBase isn't forcing the one to one relationships
  * for FileReferences, we're doing it here.
  *
  * ASSUMPTION: FileReference to File is one to one as well.
  * Meaning, deleting a FileReference will delete the File.
  *
  * NOTE: At this point, the FileReference object has not been saved
  * in the database.
  *
  * @param FileReference $fileReference
  * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object
  * @param string $fieldname
  * @param string $propertyPath
  */
 public function saveOneToOne(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, $fieldname, FileReference $fileReference, $propertyPath = 'file')
 {
     // This is a new $object, unlikely to have any existing FileReferences for this field.
     if (!$object->getUid() || $fileReference->getUid()) {
         return $this->save($fileReference, $propertyPath);
     }
     // Remove all FileReferences for this field
     $datamap = $this->dataMapper->getDataMap(get_class($object));
     $this->removeFileReferences($object->getUid(), $datamap->getTableName(), $fieldname);
     return $this->save($fileReference, $propertyPath);
 }
예제 #3
0
 /**
  * Get element uid
  *
  * @param array|DomainObjectInterface $element
  *
  * @return int|NULL
  */
 protected function getElementUid($element)
 {
     if ($element instanceof DomainObjectInterface) {
         if ($element instanceof AbstractLocalizedEntity) {
             return (int) $element->getLocalizedUid();
         }
         return (int) $element->getUid();
     }
     if (is_array($element) && isset($element['uid'])) {
         return (int) $element['uid'];
     }
     return NULL;
 }