protected function dump_base(base $base, InputInterface $input, OutputInterface $output) { $date_obj = new DateTime(); $filename = sprintf('%s%s_%s.sql', p4string::addEndSlash($input->getArgument('directory')), $base->get_dbname(), $date_obj->format('Y_m_d_H_i_s')); $command = sprintf('mysqldump %s %s %s %s %s %s --default-character-set=utf8', '--host=' . escapeshellarg($base->get_host()), '--port=' . escapeshellarg($base->get_port()), '--user='******'--password='******'--databases', escapeshellarg($base->get_dbname())); if ($input->getOption('gzip')) { $filename .= '.gz'; $command .= ' | gzip -9'; } elseif ($input->getOption('bzip')) { $filename .= '.bz2'; $command .= ' | bzip2 -9'; } $output->write(sprintf('Generating <info>%s</info> ... ', $filename)); $command .= ' > ' . escapeshellarg($filename); $process = new Process($command); $process->setTimeout((int) $input->getOption('timeout')); $process->run(); if (!$process->isSuccessful()) { $output->writeln('<error>Failed</error>'); return 1; } if (file_exists($filename) && filesize($filename) > 0) { $output->writeln('OK'); return 0; } else { $output->writeln('<error>Failed</error>'); return 1; } }
/** * Download a set of documents * * @param Application $app * @param Request $request * @param String $token * * @return Response */ public function downloadDocuments(Application $app, Request $request, $token) { $datas = $app['tokens']->helloToken($token); if (false === ($list = @unserialize((string) $datas['datas']))) { $app->abort(500, 'Invalid datas'); } $exportName = $list['export_name']; if ($list['count'] === 1) { $file = end($list['files']); $subdef = end($file['subdefs']); $exportName = sprintf('%s%s.%s', $file['export_name'], $subdef['ajout'], $subdef['exportExt']); $exportFile = \p4string::addEndSlash($subdef['path']) . $subdef['file']; $mime = $subdef['mime']; $list['complete'] = true; } else { $exportFile = $app['root.path'] . '/tmp/download/' . $datas['value'] . '.zip'; $mime = 'application/zip'; } if (!$app['filesystem']->exists($exportFile)) { $app->abort(404, 'Download file not found'); } $app['dispatcher']->addListener(KernelEvents::TERMINATE, function (PostResponseEvent $event) use($list, $app) { \set_export::log_download($app, $list, $event->getRequest()->request->get('type'), null !== $event->getRequest()->request->get('anonymous') ? true : false, isset($list['email']) ? $list['email'] : ''); }); return $app['phraseanet.file-serve']->deliverFile($exportFile, $exportName, DeliverDataInterface::DISPOSITION_ATTACHMENT, $mime); }
public static function apache_tokenize(PropertyAccess $conf, $file) { $ret = false; if ($conf->get(['registry', 'executables', 'h264-streaming-enabled']) && is_file($file)) { if (mb_strpos($file, $conf->get(['registry', 'executables', 'auth-token-directory-path'])) === false) { return false; } $server = new system_server(); if ($server->is_nginx()) { $fileToProtect = mb_substr($file, mb_strlen($conf->get(['registry', 'executables', 'auth-token-directory-path']))); $secret = $conf->get(['registry', 'executables', 'auth-token-passphrase']); $protectedPath = p4string::addFirstSlash(p4string::delEndSlash($conf->get(['registry', 'executables', 'auth-token-directory']))); $hexTime = strtoupper(dechex(time() + 3600)); $token = md5($protectedPath . $fileToProtect . '/' . $secret . '/' . $hexTime); $url = $protectedPath . $fileToProtect . '/' . $token . '/' . $hexTime; $ret = $url; } elseif ($server->is_apache()) { $fileToProtect = mb_substr($file, mb_strlen($conf->get(['registry', 'executables', 'auth-token-directory-path']))); $secret = $conf->get(['registry', 'executables', 'auth-token-passphrase']); // Same as AuthTokenSecret $protectedPath = p4string::addEndSlash(p4string::delFirstSlash($conf->get(['registry', 'executables', 'auth-token-directory']))); // Same as AuthTokenPrefix $hexTime = dechex(time()); // Time in Hexadecimal $token = md5($secret . $fileToProtect . $hexTime); // We build the url $url = '/' . $protectedPath . $token . "/" . $hexTime . $fileToProtect; $ret = $url; } } return $ret; }
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 testAddEndSlash() { $string = ''; $this->assertEquals(getcwd() . '/', p4string::addEndSlash($string)); $string = '/'; $this->assertEquals('/', p4string::addEndSlash($string)); $string = '//'; $this->assertEquals('//', p4string::addEndSlash($string)); $string = '\\'; $this->assertEquals('\\', p4string::addEndSlash($string)); $string = '\\\\'; $this->assertEquals('\\\\', p4string::addEndSlash($string)); $string = '/alalal/'; $this->assertEquals('/alalal/', p4string::addEndSlash($string)); }
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 SubdefType $type * @param SimpleXMLElement $sd * * @return databox_subdef */ public function __construct(SubdefType $type, SimpleXMLElement $sd, TranslatorInterface $translator) { $this->subdef_group = $type; $this->class = (string) $sd->attributes()->class; $this->translator = $translator; foreach ($sd->devices as $device) { $this->devices[] = (string) $device; } $this->name = strtolower($sd->attributes()->name); $this->downloadable = p4field::isyes($sd->attributes()->downloadable); $this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : ''; $this->write_meta = p4field::isyes((string) $sd->meta); foreach ($sd->label as $label) { $lang = trim((string) $label->attributes()->lang); if ($lang) { $this->labels[$lang] = (string) $label; } } switch ((string) $sd->mediatype) { default: case SubdefSpecs::TYPE_IMAGE: $this->subdef_type = $this->buildImageSubdef($sd); break; case SubdefSpecs::TYPE_AUDIO: $this->subdef_type = $this->buildAudioSubdef($sd); break; case SubdefSpecs::TYPE_VIDEO: $this->subdef_type = $this->buildVideoSubdef($sd); break; case SubdefSpecs::TYPE_ANIMATION: $this->subdef_type = $this->buildGifSubdef($sd); break; case SubdefSpecs::TYPE_FLEXPAPER: $this->subdef_type = $this->buildFlexPaperSubdef($sd); break; } return $this; }
/** * Update a record with a UUID * * @param \databox $databox * @param array $record */ protected function updateRecordUUID(\databox $databox, array $record) { $pathfile = \p4string::addEndSlash($record['path']) . $record['file']; $uuid = Uuid::uuid4(); try { $media = $this->app['mediavorus']->guess($pathfile); $collection = \collection::get_from_coll_id($this->{$app}, $databox, (int) $record['coll_id']); $file = new File($this->app, $media, $collection); $uuid = $file->getUUID(true, true); $sha256 = $file->getSha256(); $this->app['monolog']->addInfo(sprintf("Upgrading record %d with uuid %s", $record['record_id'], $uuid)); } catch (\Exception $e) { $this->app['monolog']->addError(sprintf("Uuid upgrade for record %s failed", $record['record_id'])); } $sql = 'UPDATE record SET uuid = :uuid, sha256 = :sha256 WHERE record_id = :record_id'; $params = [':uuid' => $uuid, 'sha256' => $sha256, ':record_id' => $record['record_id']]; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); }
/** * Download a set of documents * * @param Application $app * @param Request $request * @param Token $token * * @return Response */ public function downloadDocuments(Application $app, Request $request, Token $token) { if (false === ($list = @unserialize($token->getData()))) { $app->abort(500, 'Invalid datas'); } if (!is_array($list)) { $app->abort(500, 'Invalid datas'); } foreach (['export_name', 'files'] as $key) { if (!isset($list[$key])) { $app->abort(500, 'Invalid datas'); } } $exportName = $list['export_name']; if ($list['count'] === 1) { $file = end($list['files']); $subdef = end($file['subdefs']); $exportName = sprintf('%s%s.%s', $file['export_name'], $subdef['ajout'], $subdef['exportExt']); $exportFile = \p4string::addEndSlash($subdef['path']) . $subdef['file']; $mime = $subdef['mime']; $list['complete'] = true; } else { $exportFile = $app['tmp.download.path'] . '/' . $token->getValue() . '.zip'; $mime = 'application/zip'; } if (!$app['filesystem']->exists($exportFile)) { $app->abort(404, 'Download file not found'); } $app['dispatcher']->addListener(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use($list, $app) { \set_export::log_download($app, $list, $event->getRequest()->get('type'), !!$event->getRequest()->get('anonymous', false), isset($list['email']) ? $list['email'] : ''); }); return $app['phraseanet.file-serve']->deliverFile($exportFile, $exportName, DeliverDataInterface::DISPOSITION_ATTACHMENT, $mime); }
public static function dispatch(Filesystem $filesystem, $repository_path, $date = false) { if (!$date) { $date = date('Y-m-d H:i:s'); } $repository_path = p4string::addEndSlash($repository_path); $year = date('Y', strtotime($date)); $month = date('m', strtotime($date)); $day = date('d', strtotime($date)); $n = 0; $comp = $year . DIRECTORY_SEPARATOR . $month . DIRECTORY_SEPARATOR . $day . DIRECTORY_SEPARATOR; $pathout = $repository_path . $comp; while (($pathout = $repository_path . $comp . self::addZeros($n)) && is_dir($pathout) && iterator_count(new \DirectoryIterator($pathout)) > 100) { $n++; } $filesystem->mkdir($pathout, 0750); return $pathout . DIRECTORY_SEPARATOR; }
public function reset_stamp($record_id = null) { $sql = 'SELECT path, file FROM record r INNER JOIN subdef s USING(record_id) WHERE r.coll_id = :coll_id AND r.type="image" AND s.name IN ("preview", "document")'; $params = [':coll_id' => $this->get_coll_id()]; if ($record_id) { $sql .= ' AND record_id = :record_id'; $params[':record_id'] = $record_id; } $stmt = $this->get_connection()->prepare($sql); $stmt->execute($params); while ($row2 = $stmt->fetch(PDO::FETCH_ASSOC)) { @unlink(p4string::addEndSlash($row2['path']) . 'stamp_' . $row2['file']); } $stmt->closeCursor(); return $this; }
public function substitute_subdef($name, MediaInterface $media, Application $app, $adapt = true) { $newfilename = $this->record_id . '_0_' . $name . '.' . $media->getFile()->getExtension(); if ($name == 'document') { $baseprefs = $this->get_databox()->get_sxml_structure(); $pathhd = p4string::addEndSlash((string) $baseprefs->path); $filehd = $this->get_record_id() . "_document." . strtolower($media->getFile()->getExtension()); $pathhd = databox::dispatch($app['filesystem'], $pathhd); $app['filesystem']->copy($media->getFile()->getRealPath(), $pathhd . $filehd, true); $subdefFile = $pathhd . $filehd; $meta_writable = true; } else { $type = $this->isStory() ? 'image' : $this->get_type(); $subdef_def = $this->get_databox()->get_subdef_structure()->get_subdef($type, $name); if ($this->has_subdef($name) && $this->get_subdef($name)->is_physically_present()) { $path_file_dest = $this->get_subdef($name)->get_pathfile(); $this->get_subdef($name)->remove_file(); $this->clearSubdefCache($name); } else { $path = databox::dispatch($app['filesystem'], $subdef_def->get_path()); $app['filesystem']->mkdir($path, 0750); $path_file_dest = $path . $newfilename; } if ($adapt) { try { $app['media-alchemyst']->turnInto($media->getFile()->getRealPath(), $path_file_dest, $subdef_def->getSpecs()); } catch (\MediaAlchemyst\Exception\ExceptionInterface $e) { return $this; } $subdefFile = $path_file_dest; } else { $app['filesystem']->copy($media->getFile()->getRealPath(), $path_file_dest); $subdefFile = $path_file_dest; } $meta_writable = $subdef_def->meta_writeable(); } $app['filesystem']->chmod($subdefFile, 0760); $media = $app->getMediaFromUri($subdefFile); $subdef = media_subdef::create($app, $this, $name, $media); $subdef->set_substituted(true); $this->delete_data_from_cache(self::CACHE_SUBDEFS); if ($meta_writable) { $this->write_metas(); } if ($name == 'document' && $adapt) { $this->rebuild_subdefs(); } return $this; }
/** * * @param Application $app * @param String $token * @param Array $list * @param string $zipFile * * @return string */ public static function build_zip(Application $app, $token, array $list, $zipFile) { if (isset($list['complete']) && $list['complete'] === true) { return; } $files = $list['files']; $list['complete'] = false; $app['tokens']->updateToken($token, serialize($list)); $toRemove = []; $archiveFiles = []; foreach ($files as $record) { if (isset($record["subdefs"])) { foreach ($record["subdefs"] as $o => $obj) { $path = p4string::addEndSlash($obj["path"]) . $obj["file"]; if (is_file($path)) { $name = $obj["folder"] . $record["export_name"] . $obj["ajout"] . '.' . $obj["exportExt"]; $archiveFiles[$app['unicode']->remove_diacritics($name)] = $path; if ($o == 'caption') { if (!in_array(dirname($path), $toRemove)) { $toRemove[] = dirname($path); } $toRemove[] = $path; } } } } } $app['zippy']->create($zipFile, $archiveFiles); $list['complete'] = true; $app['tokens']->updateToken($token, serialize($list)); $app['filesystem']->remove($toRemove); $app['filesystem']->chmod($zipFile, 0760); return $zipFile; }
protected function doExport(Application $app, Task $task, FtpExport $export) { $settings = simplexml_load_string($task->getSettings()); $proxy = (string) $settings->proxy; $proxyport = (string) $settings->proxyport; $state = ""; $ftp_server = $export->getAddr(); $ftp_user_name = $export->getLogin(); $ftp_user_pass = $export->getPwd(); $ftpLog = $ftp_user_name . "@" . \p4string::addEndSlash($ftp_server) . $export->getDestfolder(); if ($export->getCrash() == 0) { $line = $this->translator->trans('task::ftp:Etat d\'envoi FTP vers le serveur "%server%" avec le compte "%username%" et pour destination le dossier : "%directory%"', ['%server%' => $ftp_server, '%username%' => $ftp_user_name, '%directory%' => $export->getDestfolder()]) . PHP_EOL; $state .= $line; $this->log('debug', $line); } $state .= $line = $this->translator->trans("task::ftp:TENTATIVE no %number%, %date%", ['%number%' => $export->getCrash() + 1, '%date%' => " (" . date('r') . ")"]) . PHP_EOL; $this->log('debug', $line); try { $ssl = $export->isSsl(); $ftp_client = $app['phraseanet.ftp.client']($ftp_server, 21, 300, $ssl, $proxy, $proxyport); $ftp_client->login($ftp_user_name, $ftp_user_pass); if ($export->isPassif()) { try { $ftp_client->passive(true); } catch (\Exception $e) { $this->log('debug', $e->getMessage()); } } if (trim($export->getDestfolder()) != '') { try { $ftp_client->chdir($export->getDestFolder()); $export->setDestfolder('/' . $export->getDestfolder()); } catch (\Exception $e) { $this->log('debug', $e->getMessage()); } } else { $export->setDestfolder('/'); } if (trim($export->getFoldertocreate()) != '') { try { $ftp_client->mkdir($export->getFoldertocreate()); } catch (\Exception $e) { $this->log('debug', $e->getMessage()); } try { $new_dir = $ftp_client->add_end_slash($export->getDestfolder()) . $export->getFoldertocreate(); $ftp_client->chdir($new_dir); } catch (\Exception $e) { $this->log('debug', $e->getMessage()); } } $obj = []; $basefolder = ''; if (!in_array(trim($export->getDestfolder()), ['.', './', ''])) { $basefolder = \p4string::addEndSlash($export->getDestfolder()); } $basefolder .= $export->getFoldertocreate(); if (in_array(trim($basefolder), ['.', './', ''])) { $basefolder = '/'; } foreach ($export->getElements() as $exportElement) { if ($exportElement->isDone()) { continue; } $base_id = $exportElement->getBaseId(); $record_id = $exportElement->getRecordId(); $subdef = $exportElement->getSubdef(); $localfile = null; try { $sbas_id = \phrasea::sbasFromBas($app, $base_id); $record = new \record_adapter($app, $sbas_id, $record_id); $sdcaption = $app['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_XML, $exportElement->isBusinessfields()); $remotefile = $exportElement->getFilename(); if ($subdef == 'caption') { $desc = $app['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_XML, $exportElement->isBusinessfields()); $localfile = sys_get_temp_dir() . '/' . md5($desc . time() . mt_rand()); if (file_put_contents($localfile, $desc) === false) { throw new \Exception('Impossible de creer un fichier temporaire'); } } elseif ($subdef == 'caption-yaml') { $desc = $app['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_YAML, $exportElement->isBusinessfields()); $localfile = sys_get_temp_dir() . '/' . md5($desc . time() . mt_rand()); if (file_put_contents($localfile, $desc) === false) { throw new \Exception('Impossible de creer un fichier temporaire'); } } else { $sd = $record->get_subdefs(); if (!$sd || !isset($sd[$subdef])) { continue; } $localfile = $sd[$subdef]->get_pathfile(); if (!file_exists($localfile)) { throw new \Exception('Le fichier local n\'existe pas'); } } $current_folder = rtrim(str_replace('//', '/', $basefolder . $exportElement->getFolder()), '/'); if ($ftp_client->pwd() != $current_folder) { try { $ftp_client->chdir($current_folder); } catch (\Exception $e) { $this->log('debug', $e->getMessage()); } } $ftp_client->put($remotefile, $localfile); $obj[] = ["name" => $subdef, "size" => filesize($localfile), "shortXml" => $sdcaption ? $sdcaption : '']; if ($subdef == 'caption') { unlink($localfile); } $exportElement->setDone(true)->setError(false); $app['EM']->persist($exportElement); $app['EM']->flush(); $this->logexport($app, $record, $obj, $ftpLog); } catch (\Exception $e) { $state .= $line = $this->translator->trans('task::ftp:File "%file%" (record %record_id%) de la base "%basename%" (Export du Document) : Transfert cancelled (le document n\'existe plus)', ['%file%' => basename($localfile), '%record_id%' => $record_id, '%basename%' => \phrasea::sbas_labels(\phrasea::sbasFromBas($app, $base_id), $app)]) . "\n<br/>"; $this->log('debug', $line); // One failure max $exportElement->setDone($exportElement->isError())->setError(true); $app['EM']->persist($exportElement); $app['EM']->flush(); } } if ($export->isLogfile()) { $this->log('debug', "logfile "); $date = new DateTime(); $buffer = '#transfert finished ' . $date->format(DATE_ATOM) . "\n\n"; foreach ($export->getElements() as $exportElement) { if (!$exportElement->isDone() || $exportElement->isError()) { continue; } $filename = $exportElement->getFilename(); $folder = $exportElement->getFilename(); $root = $export->getFoldertocreate(); $buffer .= $root . '/' . $folder . $filename . "\n"; } $tmpfile = sys_get_temp_dir() . '/tmpftpbuffer' . $date->format('U') . '.txt'; file_put_contents($tmpfile, $buffer); $remotefile = $date->format('U') . '-transfert.log'; $ftp_client->chdir($export->getDestFolder()); $ftp_client->put($remotefile, $tmpfile); unlink($tmpfile); } $ftp_client->close(); } catch (\Exception $e) { $state .= $line = $e . "\n"; $this->log('debug', $line); $export->incrementCrash(); $app['EM']->persist($export); $app['EM']->flush(); } $this->finalize($app, $export); }
/** * {@inheritdoc} */ protected function doJob(JobData $data) { $app = $data->getApplication(); $settings = simplexml_load_string($data->getTask()->getSettings()); $proxy = (string) $settings->proxy; $proxyport = (string) $settings->proxyport; $localPath = (string) $settings->localpath; $ftpPath = (string) $settings->ftppath; $host = (string) $settings->host; $port = (string) $settings->port; $user = (string) $settings->user; $password = (string) $settings->password; $ssl = (bool) (string) $settings->ssl; $passive = (bool) (string) $settings->passive; foreach (['localpath' => $localPath, 'host' => $host, 'port' => $host, 'user' => $user, 'password' => $password, 'ftppath' => $ftpPath] as $name => $value) { if (trim($value) === '') { // maybe throw an exception to consider the job as failing ? $this->log('error', sprintf('setting `%s` must be set', $name)); throw new RuntimeException(sprintf('`%s` setting is empty', $name)); } } $app['filesystem']->mkdir($localPath, 0750); if (!is_dir($localPath)) { $this->log('error', sprintf('`%s` does not exists', $localPath)); throw new RuntimeException(sprintf('`%s` does not exists', $localPath)); } if (!is_writeable($localPath)) { $this->log('error', sprintf('`%s` is not writeable', $localPath)); throw new RuntimeException(sprintf('`%s` is not writeable', $localPath)); } $ftp = $app['phraseanet.ftp.client']($host, $port, 90, $ssl, $proxy, $proxyport); $ftp->passive($passive); $ftp->login($user, $password); $ftp->chdir($ftpPath); $list_1 = $ftp->list_directory(true); $done = 0; $this->log('debug', "attente de 25sec pour avoir les fichiers froids..."); $this->pause(25); if (!$this->isStarted()) { $ftp->close(); $this->log('debug', "Stopping"); return; } $list_2 = $ftp->list_directory(true); foreach ($list_1 as $filepath => $timestamp) { $done++; if (!isset($list_2[$filepath])) { $this->log('debug', "le fichier {$filepath} a disparu...\n"); continue; } if ($list_2[$filepath] !== $timestamp) { $this->log('debug', "le fichier {$filepath} a ete modifie depuis le dernier passage..."); continue; } $finalpath = \p4string::addEndSlash($localPath) . ($filepath[0] == '/' ? mb_substr($filepath, 1) : $filepath); $this->log('debug', "Rappatriement de {$filepath} vers {$finalpath}\n"); if (file_exists($finalpath)) { $this->log('debug', "Un fichier du meme nom ({$finalpath}) existe deja, skipping"); continue; } $this->log('debug', "Create " . dirname($finalpath) . ""); $app['filesystem']->mkdir(dirname($finalpath), 0750); $this->log('debug', "Get {$filepath} to {$finalpath}"); $ftp->get($finalpath, $filepath); $this->log('debug', "Remove {$filepath}"); $ftp->delete($filepath); } $ftp->close(); }
/** * * @param boolean $substitute * @return media_subdef */ protected function load($substitute) { try { $datas = $this->get_data_from_cache(); $this->mime = $datas['mime']; $this->width = $datas['width']; $this->height = $datas['height']; $this->size = $datas['size']; $this->etag = $datas['etag']; $this->path = $datas['path']; $this->url = $datas['url']; $this->file = $datas['file']; $this->is_physically_present = $datas['physically_present']; $this->is_substituted = $datas['is_substituted']; $this->subdef_id = $datas['subdef_id']; $this->modification_date = $datas['modification_date']; $this->creation_date = $datas['creation_date']; return $this; } catch (\Exception $e) { } $connbas = $this->record->get_databox()->get_connection(); $sql = 'SELECT subdef_id, name, file, width, height, mime, path, size, substit, created_on, updated_on, etag FROM subdef WHERE name = :name AND record_id = :record_id'; $params = [':record_id' => $this->record->get_record_id(), ':name' => $this->name]; $stmt = $connbas->prepare($sql); $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($row) { $this->width = (int) $row['width']; $this->size = (int) $row['size']; $this->height = (int) $row['height']; $this->mime = $row['mime']; $this->file = $row['file']; $this->etag = $row['etag']; $this->path = p4string::addEndSlash($row['path']); $this->is_substituted = !!$row['substit']; $this->subdef_id = (int) $row['subdef_id']; if ($row['updated_on']) { $this->modification_date = new DateTime($row['updated_on']); } if ($row['created_on']) { $this->creation_date = new DateTime($row['created_on']); } $this->is_physically_present = true; } elseif ($substitute === false) { throw new Exception_Media_SubdefNotFound($this->name . ' not found'); } if (!$row) { $this->find_substitute_file(); } $datas = ['mime' => $this->mime, 'width' => $this->width, 'size' => $this->size, 'height' => $this->height, 'etag' => $this->etag, 'path' => $this->path, 'url' => $this->url . ($this->is_physically_present ? '?etag=' . $this->etag : ''), 'file' => $this->file, 'physically_present' => $this->is_physically_present, 'is_substituted' => $this->is_substituted, 'subdef_id' => $this->subdef_id, 'modification_date' => $this->modification_date, 'creation_date' => $this->creation_date]; $this->set_data_to_cache($datas); return $this; }