/** * @param $updatedAt * * @return $this */ public function setUpdatedAt($updatedAt) { if ($updatedAt !== $this->_authorship->createdAt()) { $dateTime = new DateTimeImmutable(date('c', $updatedAt)); $this->_authorship->update($dateTime, $this->getUserID()); } return $this; }
/** * Save the passed through data into the database and return a new instance * of the saved file object and return it. * * @param array $file data to be saved * @return File return the saved File object */ public function save(FilesystemFile $file) { $replace = $this->existsInFileManager($file); // Detect the file type $type = new Type(); $typeID = $type->guess($file); $dimensionX = null; $dimensionY = null; $authorship = new Authorship(); $authorship->create(new DateTimeImmutable(), $this->_currentUser->id); // This should be abstracted at some point if (Type::IMAGE === $typeID) { list($dimensionX, $dimensionY) = getimagesize($file->getPathname()); } if ($replace) { $oldFile = $this->_loader->includeDeleted(true)->getByID($replace); $this->_loader->includeDeleted(false); // if file is not deleted then reject if (!$oldFile->authorship->isDeleted()) { throw new Exception\FileExists('File already exists in File Manager', $replace); } $result = $this->_query->run(' REPLACE INTO file SET file_id = :id?i, url = :url?s, name = :name?s, extension = :extension?s, file_size = :size?i, created_at = :createdAt?d, created_by = :createdBy?i, type_id = :typeID?i, checksum = :checksum?s, preview_url = :previewUrl?sn, dimension_x = :dimX?in, dimension_y = :dimY?in, duration = :duration?in, alt_text = :altText?s ', ['id' => $replace, 'url' => $file->getPathname(), 'name' => $file->getFilename(), 'extension' => $file->getExtension(), 'size' => $file->getSize(), 'createdAt' => $authorship->createdAt(), 'createdBy' => $authorship->createdBy(), 'typeID' => $typeID, 'checksum' => $file->getChecksum(), 'previewUrl' => null, 'dimX' => $dimensionX, 'dimY' => $dimensionY, 'duration' => null, 'altText' => $oldFile->altText]); } else { $result = $this->_query->run(' INSERT INTO file SET url = :url?s, name = :name?s, extension = :extension?s, file_size = :size?i, created_at = :createdAt?d, created_by = :createdBy?i, type_id = :typeID?i, checksum = :checksum?s, preview_url = :previewUrl?sn, dimension_x = :dimX?in, dimension_y = :dimY?in, duration = :duration?in ', array('url' => $file->getPathname(), 'name' => $file->getFilename(), 'extension' => $file->getExtension(), 'size' => $file->getSize(), 'createdAt' => $authorship->createdAt(), 'createdBy' => $authorship->createdBy(), 'typeID' => $typeID, 'checksum' => $file->getChecksum(), 'previewUrl' => null, 'dimX' => $dimensionX, 'dimY' => $dimensionY, 'duration' => null)); } // Load the file we just saved as an object $file = $this->_loader->getByID($result->id()); // Initiate the event $event = new Event($file); // Dispatch the file created event $this->_eventDispatcher->dispatch($event::CREATE, $event); // Return the File object from the event return $event->getFile(); }
private function _addAuthorship() { $authorship = new Authorship(); $authorship->create(null, $this->_user); $this->_unit->authorship = $authorship; }
/** * {@inheritDoc} */ public function getLastModified() { return $this->authorship->updatedAt(); }