Beispiel #1
0
 /**
  * Convert a file representation to File Resource.
  *
  * @param Content|int $fileRepresentation
  * @throws \RuntimeException
  * @return File
  */
 public function convert($fileRepresentation)
 {
     if ($fileRepresentation instanceof Content) {
         $fileData = $fileRepresentation->toArray();
         if (!isset($fileData['storage']) && $fileData['storage'] === NULL) {
             throw new \RuntimeException('Storage identifier can not be null.', 1379946981);
         }
         $fileUid = $fileData['uid'];
     } else {
         $fileData = array();
         $fileUid = (int) $fileRepresentation;
     }
     return ResourceFactory::getInstance()->getFileObject($fileUid, $fileData);
 }
Beispiel #2
0
 /**
  * Process Content with action "update".
  *
  * @param Content $content
  * @throws \Exception
  * @return bool
  */
 public function processUpdate(Content $content)
 {
     $values = array();
     // Check the field to be updated exists
     foreach ($content->toArray() as $fieldName => $value) {
         if (!Tca::table($content->getDataType())->hasField($fieldName)) {
             $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType());
             throw new \Exception($message, 1390668497);
         }
         // Flatten value if array given which is required for the DataHandler.
         if (is_array($value)) {
             $value = implode(',', $value);
         }
         $values[$fieldName] = $value;
     }
     $data[$content->getDataType()][$content->getUid()] = $values;
     $dataHandler = $this->getDataHandler();
     $dataHandler->start($data, array());
     $dataHandler->process_datamap();
     $this->errorMessages = $dataHandler->errorLog;
     // Returns TRUE is log does not contain errors.
     return empty($dataHandler->errorLog);
 }