private function generateSubdefPathname(\record_adapter $record, \databox_subdef $subdef, $oldVersion = null) { if ($oldVersion) { $pathdest = \p4string::addEndSlash(pathinfo($oldVersion, PATHINFO_DIRNAME)); } else { $pathdest = \databox::dispatch($this->filesystem, $subdef->get_path()); } return $pathdest . $record->get_record_id() . '_' . $subdef->get_name() . '.' . $this->getExtensionFromSpec($subdef->getSpecs()); }
public function substitute(\record_adapter $record, $name, MediaInterface $media) { $newfilename = $record->get_record_id() . '_0_' . $name . '.' . $media->getFile()->getExtension(); $subdef_def = false; if ($name == 'document') { $baseprefs = $record->get_databox()->get_sxml_structure(); $pathhd = \p4string::addEndSlash((string) $baseprefs->path); $filehd = $record->get_record_id() . "_document." . strtolower($media->getFile()->getExtension()); $pathhd = \databox::dispatch($this->fs, $pathhd); $this->fs->copy($media->getFile()->getRealPath(), $pathhd . $filehd, true); $subdefFile = $pathhd . $filehd; $meta_writable = true; } else { $type = $record->isStory() ? 'image' : $record->get_type(); $subdef_def = $record->get_databox()->get_subdef_structure()->get_subdef($type, $name); if ($record->has_subdef($name) && $record->get_subdef($name)->is_physically_present()) { $path_file_dest = $record->get_subdef($name)->get_pathfile(); $record->get_subdef($name)->remove_file(); $record->clearSubdefCache($name); } else { $path = \databox::dispatch($this->fs, $subdef_def->get_path()); $this->fs->mkdir($path, 0750); $path_file_dest = $path . $newfilename; } try { $this->alchemyst->turnInto($media->getFile()->getRealPath(), $path_file_dest, $subdef_def->getSpecs()); } catch (MediaAlchemystException $e) { return; } $subdefFile = $path_file_dest; $meta_writable = $subdef_def->meta_writeable(); } $this->fs->chmod($subdefFile, 0760); $media = $this->mediavorus->guess($subdefFile); \media_subdef::create($this->app, $record, $name, $media); $record->delete_data_from_cache(\record_adapter::CACHE_SUBDEFS); if ($meta_writable) { $record->write_metas(); } if ($name == 'document') { $record->rebuild_subdefs(); } $this->dispatcher->dispatch(RecordEvents::MEDIA_SUBSTITUTED, new RecordMediaSubstitutedEvent($record)); }
/** * * @param File $file * @param Application $app * * @return \record_adapter */ public static function createFromFile(File $file, Application $app) { $databox = $file->getCollection()->get_databox(); $sql = 'INSERT INTO record (coll_id, record_id, parent_record_id, moddate, credate , type, sha256, uuid, originalname, mime) VALUES (:coll_id, null, :parent_record_id, NOW(), NOW() , :type, :sha256, :uuid , :originalname, :mime)'; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute([':coll_id' => $file->getCollection()->get_coll_id(), ':parent_record_id' => 0, ':type' => $file->getType() ? $file->getType()->getType() : 'unknown', ':sha256' => $file->getMedia()->getHash('sha256'), ':uuid' => $file->getUUID(true), ':originalname' => $file->getOriginalName(), ':mime' => $file->getFile()->getMimeType()]); $record_id = $databox->get_connection()->lastInsertId(); $record = new self($app, $databox->get_sbas_id(), $record_id); try { $log_id = $app['phraseanet.logger']($databox)->get_id(); $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment) VALUES (null, :log_id, now(), :record_id, "add", :coll_id,"")'; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute([':log_id' => $log_id, ':record_id' => $record_id, ':coll_id' => $file->getCollection()->get_coll_id()]); $stmt->closeCursor(); } catch (\Exception $e) { unset($e); } $pathhd = databox::dispatch($app['filesystem'], trim($databox->get_sxml_structure()->path)); $newname = $record->get_record_id() . "_document." . pathinfo($file->getOriginalName(), PATHINFO_EXTENSION); $app['filesystem']->copy($file->getFile()->getRealPath(), $pathhd . $newname, true); $media = $app['mediavorus']->guess($pathhd . $newname); media_subdef::create($app, $record, 'document', $media); $record->delete_data_from_cache(\record_adapter::CACHE_SUBDEFS); $record->insertTechnicalDatas($app['mediavorus']); $record->rebuild_subdefs(); return $record; }