Пример #1
0
 public function __construct()
 {
     $this->config = core_config();
     if (is_null(static::$logger)) {
         static::$logger = new Logger('ingest');
         $logname = core_config('logs.path') . DS . 'activity.log';
         static::$logger->pushHandler(new StreamHandler($logname, Logger::DEBUG));
     }
     if (is_null(static::$manager)) {
         if (core_config()->has('default.local') && core_config()->has('staging.local')) {
             $default = new Local(core_config('default.local'));
             $staging = new Local(core_config('staging.local'));
             $public = new Local(core_config('public.local'));
             $defaultIfc = new Filesystem($default);
             $stagingIfc = new Filesystem($staging);
             $publicIfc = new Filesystem($public);
         } else {
             print "The system is not fully configured: default.local and staging.local must both be set.\n";
             return false;
         }
         static::$manager = new MountManager(['default' => $defaultIfc, 'staging' => $stagingIfc, 'public' => $publicIfc]);
         static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': ========= MARK: INIT =========');
     }
     if (is_null(static::$disk)) {
         $this->initDiskMap();
     }
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     $this->scanlog = new Logger('scanlog');
     $logname = core_config('logs.path') . DS . 'health_check.log';
     $this->scanlog->pushHandler(new StreamHandler($logname, Logger::DEBUG));
     $this->config = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(core_config_path() . '/core.yaml'));
     print_r($this->config);
 }
Пример #3
0
 private function initLogger()
 {
     $this->config = core_config();
     if (is_null($this->logger)) {
         $this->logger = new Logger('ingest');
         $logname = core_config('logs.path') . DS . 'activity.log';
         $this->logger->pushHandler(new StreamHandler($logname, Logger::DEBUG));
     }
 }
Пример #4
0
 public function __construct(ContainerInterface $ci)
 {
     $this->ci = $ci;
     $this->views = new Engine(core_config('views.path'));
     $this->views->addFolder('layouts', core_config('views.layouts.path'));
     $this->views->addFolder('errors', core_config('views.errors.path'));
     $this->views->addFolder('api', core_config('views.api.path'));
     $this->config = core_config();
     if (is_null($this->logger)) {
         $this->logger = new Logger('ingest');
         $logname = core_config('logs.path') . DS . 'activity.log';
         $this->logger->pushHandler(new StreamHandler($logname, Logger::DEBUG));
     }
 }
Пример #5
0
 public function fetchImage($uuid, $width = null, $height = null)
 {
     $asset = static::$disk->asset($uuid);
     $collection = $asset->parent();
     $volume = $collection->parent();
     //        $disk = $volume->parent()->name();
     $filename = $volume . DS . $collection . DS . $uuid . '.' . $asset->extension();
     // disk mapping ...
     $path = core_config('default.local');
     //        static::$logger->info(__CLASS__.'::'.__FUNCTION__.': DEFAULT LOCAL: '. $path );
     $this->real_root = realpath($path . DS . $filename);
     //        static::$logger->info(__CLASS__.'::'.__FUNCTION__.': REAL ROOT: '.$this->real_root);
     $this->content = file_get_contents($this->real_root);
     return $this->scaleImage($asset, $width, $height);
 }
 /**
  * @param $asset_path
  * @return string|void          json encoded metadata collection for asset given
  * @throws \Exception
  */
 public function analyze($asset_path)
 {
     $msg = "Received path spec:  {$asset_path}";
     $this->report[] = $msg;
     static::$logger->addInfo($msg);
     if (static::$manager->has($asset_path)) {
         $msg = "File not found at path:  {$asset_path}";
         $this->report[] = $msg;
         static::$logger->addInfo($msg);
     }
     $mimes = new MimeTypes();
     $mimeType = $mimes->getMimeType(pathinfo($asset_path, PATHINFO_EXTENSION));
     $msg = "Selecting analyzer by mime-type: {$mimeType}";
     $this->report[] = $msg;
     static::$logger->addInfo($msg);
     if (strpos($asset_path, '://') !== false) {
         list($protocol, $path) = explode('://', $asset_path);
     } else {
         $protocol = 'default';
         $path = $asset_path;
     }
     $base_path = core_config($protocol . '.local');
     $abs_file_path = $base_path . DS . $path;
     $msg = "Derived absolute path to asset file: {$abs_file_path}";
     $this->report[] = $msg;
     static::$logger->addInfo($msg);
     // TODO make this external - config values
     $ffprobe_config = array('ffmpeg.binaries' => '/usr/bin/ffmpeg', 'ffprobe.binaries' => '/usr/bin/ffprobe', 'timeout' => 3600, 'ffmpeg.threads' => 12);
     if (strpos($mimeType, 'image') === 0) {
         return $this->ingestImageAsset($abs_file_path, $mimeType, $ffprobe_config);
     } elseif (strpos($mimeType, 'video') === 0) {
         return $this->ingestVideoAsset($abs_file_path, $mimeType, $ffprobe_config);
     } elseif (strpos($mimeType, 'audio') !== false) {
         return $this->ingestAudioAsset($abs_file_path, $mimeType, $ffprobe_config);
     } elseif (strpos($mimeType, 'text') !== false) {
         return $this->ingestTextAsset($abs_file_path, $mimeType, $ffprobe_config);
     } elseif (strpos($mimeType, 'json') !== false) {
         return $this->ingestJSONAsset($abs_file_path, $mimeType, $ffprobe_config);
     } elseif (strpos($mimeType, 'msword') !== false) {
         return $this->ingestMSWordAsset($abs_file_path, $mimeType, $ffprobe_config);
     } elseif (strpos($mimeType, 'pdf') !== false) {
         return $this->ingestPDFAsset($abs_file_path, $mimeType, $ffprobe_config);
     } else {
         $mimeType = 'other';
         return $this->ingestOtherAsset($abs_file_path, $mimeType, $ffprobe_config);
     }
 }
Пример #7
0
 private function fetchOrCreateSchemaObject($schema_id, $props = [], $head = [])
 {
     //        static::$logger->debug(__CLASS__.'::'.__FUNCTION__.': schema_id: '.$schema_id .', ['.implode(',',array_keys($this->schemas())).']' );
     if (in_array($schema_id, array_keys($this->schemas()))) {
         // if schema already exists, leave the head+props data alone
         static::$logger->debug(__CLASS__ . '::' . __FUNCTION__ . ': fetching existing schema');
         return $this->schema($schema_id);
     }
     if (count($head) === 0) {
         if (!isset($props['id'])) {
             $file = str_replace('/', '-', $schema_id);
             $props['id'] = 'http://api.repose.dev/draft/' . $file . '#';
         }
         if (!isset($props['schema'])) {
             $props['schema'] = core_config('schemaSchema');
         }
         if (!isset($props['type'])) {
             $props['type'] = 'object';
         }
     } else {
         if (!isset($head['id'])) {
             $file = str_replace('/', '-', $schema_id);
             $head['id'] = 'http://api.repose.dev/draft/' . $file . '#';
         }
         if (!isset($head['schema'])) {
             $head['schema'] = core_config('schemaSchema');
         }
         if (!isset($head['type'])) {
             $head['type'] = 'object';
         }
     }
     //        static::$logger->debug( __CLASS__.'::'.__FUNCTION__.': fetching newly created schema');
     return new Schema($schema_id, $props, $head);
 }
Пример #8
0
 public function __construct()
 {
     parent::__construct();
     $this->log_dir = core_config('logs.path');
 }
Пример #9
0
 public function upload(Request $request)
 {
     // Slim's way of getting it all at once
     // $data = $request->getParsedBody();
     $staging = core_config('staging.local');
     //        $disk_name = $_POST['disk_name'];
     //        $volume_name = $_POST['volume_name'];
     //        $collection_name = $_POST['collection_name'];
     $form_data = $request->getParsedBody();
     $disk_name = $form_data['disk_name'];
     if (!$disk_name || $disk_name === DS) {
         $disk_name = 'default' . DS;
     }
     $volume_name = $form_data['volume_name'];
     $collection_name = $form_data['collection_name'];
     static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': looking for staging directory: ' . $volume_name . $collection_name);
     try {
         if (!static::$manager->has('staging://' . $disk_name . $volume_name . $collection_name)) {
             static::$manager->createDir('staging://' . $disk_name . $volume_name . $collection_name);
             static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': created staging directory: ' . $staging . DS . $disk_name . $volume_name . $collection_name);
             $this->report[] = ['collection' => 'created'];
         } else {
             static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': found staging directory: ' . $staging . DS . $disk_name . $volume_name . $collection_name);
             $this->report[] = ['collection' => 'found'];
         }
     } catch (\Exception $e) {
         $this->errors[] = ['collection' => $e->getMessage()];
         static::$logger->addDebug(__CLASS__ . '::' . __FUNCTION__ . ': Exception ' . $e->getMessage());
         return false;
     }
     //        static::$logger->addDebug( __CLASS__.'::'.__FUNCTION__.': '.json_encode($_FILES,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
     try {
         $count = 0;
         foreach ($_FILES['file']['name'] as $filename) {
             //                static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': handling upload file: '.json_encode($filename,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) );
             if ($_FILES['file']['error'][$count] === UPLOAD_ERR_OK) {
                 $tmpFile = $_FILES['file']['tmp_name'][$count];
                 $count++;
                 // always increment, even for empty file spaces
                 if ($tmpFile !== '') {
                     // but save no empty files please
                     $tempTarget = $staging . DS . $disk_name . $volume_name . $collection_name . basename($filename);
                     move_uploaded_file($tmpFile, $tempTarget);
                     static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': uploaded: ' . $tempTarget);
                     $this->report[] = ['file' . $count => 'uploaded'];
                 }
                 // reset
                 $tempTarget = '';
                 $tmpFile = '';
             } else {
                 static::$logger->addAlert(__CLASS__ . '::' . __FUNCTION__ . ': throwing a hissy fit: upload error code:' . $_FILES['file']['error'][$count]);
                 throw new UploadException($_FILES['file']['error'][$count]);
             }
         }
     } catch (UploadException $e) {
         $this->errors[] = ['file' . $count => $e->getMessage()];
         static::$logger->addDebug(__CLASS__ . '::' . __FUNCTION__ . ': Exception ' . $e->getMessage());
         return false;
     }
     return true;
 }