/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->output->progressStart();
     $offset = 0;
     $media = Media::with('mediaType', 'scan', 'scan.specimen', 'scan.museum', 'scan.author', 'scan.animalGroup')->limit(self::BATCH_LIMIT)->offset($offset)->get()->toArray();
     while (!empty($media)) {
         foreach ($media as $key => $mediaArray) {
             $media[$key] = $this->flattenNested($mediaArray, true);
         }
         $this->output->progressAdvance(self::BATCH_LIMIT);
         $this->search->insertDocuments($media);
         $offset += self::BATCH_LIMIT;
         $media = Media::with('mediaType', 'scan', 'scan.specimen', 'scan.museum', 'scan.author', 'scan.animalGroup')->limit(self::BATCH_LIMIT)->offset($offset)->get()->toArray();
     }
     $offset = 0;
     $images = Image::with('scan', 'scan.specimen', 'scan.museum', 'scan.author', 'scan.animalGroup')->limit(self::BATCH_LIMIT)->offset($offset)->get()->toArray();
     while (!empty($images)) {
         foreach ($images as $key => $image) {
             $images[$key] = $this->flattenNested($image, true);
         }
         $this->output->progressAdvance(self::BATCH_LIMIT);
         $this->search->insertDocuments($images);
         $offset += self::BATCH_LIMIT;
         $images = Image::with('scan', 'scan.specimen', 'scan.museum', 'scan.author', 'scan.animalGroup')->limit(self::BATCH_LIMIT)->offset($offset)->get()->toArray();
     }
     $this->output->progressFinish();
 }
Exemplo n.º 2
0
 public function getDownload($assetID)
 {
     $asset = \App\Models\Media::find($assetID);
     if (!$asset) {
         abort(404);
     }
     ob_clean();
     return response()->download($asset->filePath('o'));
 }
Exemplo n.º 3
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $table_file = 'File';
     // capital in mysql !
     $table_job = 'Job';
     // capital in mysql !
     $timediff = null;
     $hoursdiff = null;
     $hoursbytes = null;
     /* Get Database Size */
     if (\Config::get('database.default') == 'mysql') {
         $dbsize = \DB::select('SELECT table_schema "Data Base Name",
                         SUM( data_length + index_length) / 1024 / 1024 "dbsize"
                         FROM information_schema.TABLES
                         WHERE table_schema = "' . \Config::get('database.connections.mysql.database') . '"
                         GROUP BY table_schema ;');
     } else {
         $dbsize = \DB::select("SELECT pg_database_size('" . \Config::get('database.connections.pgsql.database') . "') as dbsize");
     }
     // Get Server Hostname
     $servername = gethostname();
     // Get Number of Clients
     $clientsNumber = Client::all()->count();
     // Get Number of Files Transfered
     $filesNumber = \DB::table($table_file)->select(\DB::raw('count(*) AS filesNumber'))->get();
     // Get Storage Bytes
     $bytesStorage = Media::sum('volbytes');
     //* Query For Hour Starts
     $dataInicio = date('Y-m-d', strtotime("-1 days")) . ' 18:29';
     $dataFim = date('Y-m-d') . ' 18:29';
     if (\Config::get('database.default') == 'mysql') {
         /* Query timediff Stats */
         $timediff = \DB::table($table_job)->select(\DB::raw('TIMEDIFF(max(starttime) , min(starttime)) AS timediff'))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
         $hoursdiff = \DB::table($table_job)->select(\DB::raw("(HOUR(TIMEDIFF(max(starttime), min(starttime))) + (MINUTE(TIMEDIFF(max(starttime) , min(starttime))) / 60.0)) AS hoursdiff"))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
         $hoursbytes = \DB::table($table_job)->select(\DB::raw("(sum(jobbytes)/(HOUR(TIMEDIFF(max(starttime) , min(starttime))) + (MINUTE(TIMEDIFF(max(starttime) , min(starttime))) / 60.0))) AS hoursbytes"))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
         $query = \DB::table($table_job)->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim);
         $fnumber = $filesNumber[0]->filesNumber;
     } elseif (\Config::get('database.default') == 'pgsql') {
         /* Query timediff Stats */
         $timediff = \DB::table($table_job)->select(\DB::raw('(max(starttime) - min(starttime)) AS timediff'))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
         $hoursdiff = \DB::table($table_job)->select(\DB::raw("(date_part('hour',  (max(starttime) - min(starttime))) + (date_part('minutes',  (max(starttime) - min(starttime))) / 60.0)) AS hoursdiff"))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
         $hoursbytes = \DB::table($table_job)->select(\DB::raw("(sum(jobbytes)/(date_part('hour',  (max(starttime) - min(starttime))) + (date_part('minutes',  (max(starttime) - min(starttime))) / 60.0))) AS hoursbytes"))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
         $query = \DB::table($table_job)->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim);
         $fnumber = $filesNumber[0]->filesnumber;
     }
     $jobbytes = $query->sum('jobbytes');
     $starttime = $query->min('starttime');
     $endtime = $query->max('endtime');
     /* Data for Stats to Insert*/
     $daystats = array('data' => date('Y-m-d'), 'server' => $servername, 'bytes' => $bytesStorage, 'files' => $fnumber, 'clients' => $clientsNumber, 'databasesize' => $dbsize[0]->dbsize);
     $hourstats = array('data' => date('Y-m-d'), 'server' => $servername, 'bytes' => $jobbytes, 'starttime' => $starttime, 'endtime' => $endtime, 'timediff' => $timediff[0]->timediff, 'hoursdiff' => (int) $hoursdiff[0]->hoursdiff, 'hourbytes' => $hoursbytes[0]->hoursbytes);
     Hoursstats::firstOrCreate($hourstats);
     Daystats::firstOrCreate($daystats);
 }
 protected function filter_project_input()
 {
     $input = Input::all();
     foreach (['profile', 'cover'] as $name) {
         if (Input::file($name) && Input::file($name)->isValid()) {
             $res = \Cloudinary\Uploader::upload(Input::file($name)->getRealPath());
             if ($res && isset($res['public_id'])) {
                 $media = Media::create(['public_id' => $res['public_id']]);
                 $input[$name . '_media_id'] = $media->id;
             }
             unset($input[$name]);
         }
     }
     return $input;
 }
 public function run()
 {
     if (class_exists('Faker\\Factory')) {
         $faker = Faker\Factory::create();
         $images = ['img/eusthenopteron_foordi.jpg', 'img/iridotriton_hechti.jpg', 'img/sipalocyon_sp.jpg', 'img/teinolophos_trusleri.jpg'];
         $scans = Scan::all()->all();
         $mediaTypes = MediaType::all()->all();
         foreach ($scans as $scan) {
             $count = $faker->randomDigit;
             for ($i = 1; $i <= $count; $i++) {
                 Media::create(['filePath' => '/' . $faker->word, 'fileName' => $faker->word . $faker->randomNumber(2) . '.' . $faker->randomElement(['stl', 'vgl', 'mov', 'dct']), 'fileUrl' => $faker->randomElement($images), 'scanId' => $scan->id, 'mediaTypeId' => $faker->randomElement($mediaTypes)->id]);
             }
         }
     }
 }
Exemplo n.º 6
0
 public function insertStats()
 {
     /* Get Database Size */
     if (Config::get('database.default') == "mysql") {
         $dbsize = DB::select('SELECT table_schema "Data Base Name",
                         SUM( data_length + index_length) / 1024 / 1024 "dbsize"
                         FROM information_schema.TABLES
                         WHERE table_schema = "' . Config::get('database.connections.mysql.database') . '"
                         GROUP BY table_schema ;');
     } else {
         $dbsize = DB::select("SELECT pg_database_size('" . Config::get('database.connections.pgsql.database') . "') as dbsize");
     }
     // Get Server Hostname
     $servername = gethostname();
     // Get Number of Clients
     $clientsNumber = Client::all()->count();
     // Get Number of Files Transfered
     $filesNumber = DB::table('file')->select(DB::raw('count(*) AS filesNumber'))->get();
     // Get Storage Bytes
     $bytesStorage = Media::sum('volbytes');
     //* Query For Hour Starts
     $dataInicio = date('Y-m-d', strtotime("-1 days")) . ' 18:29';
     $dataFim = date('Y-m-d') . ' 18:29';
     /* Query timediff Stats */
     $timediff = DB::table('job')->select(DB::raw('(max(starttime) - min(starttime)) AS timediff'))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
     $hoursdiff = DB::table('job')->select(DB::raw("date_part('hour',  (max(starttime) - min(starttime))) AS hoursdiff"))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
     $hoursbytes = DB::table('job')->select(DB::raw("(sum(jobbytes)/date_part('hour',  (max(starttime) - min(starttime)))) AS hoursbytes"))->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim)->get();
     $query = DB::table('job')->where('starttime', '>=', $dataInicio)->where('endtime', '<=', $dataFim);
     $jobbytes = $query->sum('jobbytes');
     $starttime = $query->min('starttime');
     $endtime = $query->max('endtime');
     /* Data for Stats to Insert*/
     $daystats = array('data' => date('Y-m-d'), 'server' => $servername, 'bytes' => $bytesStorage, 'files' => $filesNumber[0]->filesnumber, 'clients' => $clientsNumber, 'databasesize' => $dbsize[0]->dbsize);
     $hourstats = array('data' => date('Y-m-d'), 'server' => $servername, 'bytes' => $jobbytes, 'starttime' => $starttime, 'endtime' => $endtime, 'timediff' => $timediff[0]->timediff, 'hoursdiff' => $hoursdiff[0]->hoursdiff, 'hourbytes' => $hoursbytes[0]->hoursbytes);
     $hourstats = Hoursstats::firstOrCreate($hourstats);
     $daystats = Daystats::firstOrCreate($daystats);
     $t = Hoursstats::insert($hourstats);
     $d = Daystats::insert($daystats);
 }
Exemplo n.º 7
0
 public function volumes($volumes = null)
 {
     $volumeSelected = Input::get('Volume', $volumes);
     $media = Media::where('mediaid', '=', $volumeSelected)->first();
     if ($media == Null) {
         $slot = "";
         $pool = "";
         $firstwritten = "";
         $lastwritten = "";
         $labeldate = "";
         $voljobs = "";
         $volfiles = "";
         $labeldate = "";
         $volretention = "";
         $volbytes = "";
         $volstatus = "";
         $volumeSelected = "";
     } else {
         $slot = $media->slot;
         $pool = $media->pool;
         $firstwritten = $media->firstwritten;
         $lastwritten = $media->lastwritten;
         $labeldate = $media->labeldate;
         $voljobs = $media->voljobs;
         $volfiles = $media->volfiles;
         $labeldate = $media->labeldate;
         $to = Date::now();
         $text = " Days";
         /* 86400  -> equal to seconds in i day*/
         $volretention = $media->volretention / 86400 . $text;
         if ($volretention >= 365) {
             $type = ' Year';
             $volretention = intval($volretention / 31536000) . $type;
         }
         $volbytes = $this->byte_format($media->VolBytes);
         $volstatus = $media->volstatus;
     }
     return View::make('volumes', array('slot' => $slot, 'volume' => $volumeSelected, 'firstwritten' => $firstwritten, 'lastwritten' => $lastwritten, 'labeldate' => $labeldate, 'voljobs' => $voljobs, 'volfiles' => $volfiles, 'labeldate' => $labeldate, 'volretention' => $volretention, 'volbytes' => $volbytes, 'volstatus' => $volstatus, 'volumeSelectBox' => $this->volumeSelectBox));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     $media = Media::find($id);
     $this->checkExist($media);
     $media->delete();
     return response()->return();
 }
Exemplo n.º 9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMedia()
 {
     return $this->hasMany(Media::className(), ['user' => 'ID']);
 }
Exemplo n.º 10
0
 public function getpools()
 {
     $pool = Input::get('Pool', "");
     $volumes = Media::select(array('mediaid', 'volumename', 'slot', 'mediatype', 'lastwritten', 'voljobs', 'volfiles', 'volbytes', 'volretention', 'volstatus'))->where('poolid', '=', $pool);
     return Datatables::of($volumes)->edit_column('volretention', '{{ date("d", $volretention)." Days" }}')->edit_column('volumename', '{{ link_to_route("volumes", $volumename ,array("Volume" => $mediaid)) }} ')->remove_column('mediaid')->make();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     $media = Media::find($id);
     if (is_null($media)) {
         throw new NotFoundException();
     }
     $media->delete();
     return response()->return();
 }
Exemplo n.º 12
0
 public function cover_url($style = array())
 {
     return Media::url($this->cover, $style, getenv('CLOUDINARY_DEFAULT_COVER'));
 }
Exemplo n.º 13
0
 public function getImage($width_height, $file_name)
 {
     $media_id = (int) \Input::get('mid');
     $canvas_color = 'FFFFFF';
     if ($media_id) {
         $media_model = \App\Models\Media::findOrFail($media_id);
         $canvas_color = $media_model->canvas_color;
         if (empty($media_model->file_name) and !empty($media_model->source_url)) {
             $file_extention = 'jpg';
             $file_name = md5(microtime() . rand(0, 1000)) . '.' . $file_extention;
             $source_url = $media_model->source_url;
             if (substr($source_url, 0, 7) != 'http://' and substr($source_url, 0, 8) != 'https://') {
                 $source_url = 'http://' . $source_url;
             }
             \Storage::put('media/images/' . $file_name, file_get_contents($source_url));
             $media_model->file_name = $file_name;
             $media_model->save();
         }
     }
     $width_height_arr = explode('x', $width_height);
     $width = $width_height_arr[0];
     $height = $width_height_arr[1];
     $image_path = $this->getOriginDir() . $file_name;
     if (!file_exists($image_path)) {
         $img = Image::canvas($width, $height);
         $img->text('Image not found ;{', 110, 110, function ($font) {
             $font->size(48);
             $font->align('center');
         });
         return $img->response('jpg');
     }
     $img = Image::make($image_path);
     $source_width = $img->width();
     $source_height = $img->height();
     if ($source_width < $source_height) {
         if ($width = $height or $width > $height) {
             // resize H
             $img->heighten($height);
         }
     } elseif ($source_width > $source_height) {
         if ($width = $height or $width < $height) {
             // resize V
             $img->widen($width);
         }
     } else {
         if ($width > $height) {
             // resize H
             $img->heighten($height);
         }
         if ($width < $height) {
             // resize V
             $img->widen($width);
         }
     }
     $img->resizeCanvas($width, $height, 'center', false, $canvas_color);
     //$img->fit($width, $height);
     $storage_dir = base_path() . '/public/media/images/' . $width_height;
     $storage_file = $storage_dir . '/' . $file_name;
     if (!file_exists($storage_dir)) {
         mkdir($storage_dir);
     }
     $img->save($storage_file);
     return $img->response('jpg');
 }
Exemplo n.º 14
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMedia()
 {
     return $this->hasOne(Media::className(), ['ID' => 'media']);
 }
Exemplo n.º 15
0
 public function editWish($id)
 {
     //  return response()->json(['result' => 'success', 'data' => $text], 200);
     $wish = Wish::where('id', $id)->first();
     if ($wish) {
         $wish->name = Input::get('name');
         $wish->description = Input::get('description');
         $wish->category_id = Input::get('category')['id'];
         $wish->link = Input::get('link');
         $text = Input::get("photo");
         if (isset($text['$ngfDataUrl'])) {
             $destinationPath = 'images/wishes/';
             $data = $text['$ngfDataUrl'];
             list($type, $data) = explode(';', $data);
             list(, $type) = explode('/', $type);
             list(, $data) = explode(',', $data);
             $fileName = md5(date("YmdHis") . rand(5, 50)) . '.' . $type;
             $data = base64_decode($data);
             $media = Media::where('id', $wish->media_id)->first();
             if (file_put_contents($destinationPath . $fileName, $data)) {
                 if ($media->id != 3) {
                     $tmp = $media->name;
                     $media->name = URL::to('/') . "/" . $destinationPath . $fileName;
                     $media->save();
                     $arr = explode("/", $tmp);
                     unlink($destinationPath . $arr[count($arr) - 1]);
                 } else {
                     $media = new Media();
                     $media->name = URL::to('/') . "/" . $destinationPath . $fileName;
                     $media->save();
                     $wish->media_id = $media->id;
                 }
             }
         }
         $wish->save();
         return response()->json(['result' => 'success'], 200);
     } else {
         return response()->json(['result' => 'error'], 200);
     }
 }
Exemplo n.º 16
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return array_merge(parent::attributeLabels(), ['url' => '视频链接', 'imageFile' => '缩略图', 'author' => '作者', 'editor' => '编辑', 'category' => '分类']);
 }
 public function destroy($pk)
 {
     // Check if primary_key matching $pk exist
     if (!$this->rowExist($this->model, $pk)) {
         Flash::error(trans($this->trans_path . 'general.error.no-data-found'));
         return $this->redirectToRoute();
     }
     $productModel = $this->model;
     $productDataModel = $this->productBasketData;
     $productData = $productDataModel::where('product_id', $pk)->first();
     // Remove Main Product Image
     if ($productData->image) {
         parent::__unlinkFile($this->imagePath, $productData->image);
         parent::__unlinkFileThumbnails($this->thumbnail_dimensions, $this->imagePath, $productData->image);
     }
     // Remove Multiple Images for Product
     $imgs = ProductMedia::where('product_id', $pk)->get(['id', 'media_id']);
     foreach ($imgs as $img) {
         $mediaObj = Media::find($img->media_id);
         // Remove old image
         parent::__unlinkFile($this->imagePath, $mediaObj->media);
         parent::__unlinkFileThumbnails($this->imgGalleryThumbDimension, $this->imagePath, $mediaObj->media);
         // Remove Data Form Media Table
         // This will remove child ProductMedia Data
         $mediaObj->delete();
     }
     // Remove Product
     // Product Attribute Value and Media Data
     // will be removed automatically due to FKey relation
     $productModel::pk($pk)->delete();
     Flash::success(trans($this->trans_path . 'general.status.deleted'));
     return $this->redirectToRoute();
 }
Exemplo n.º 18
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMedia()
 {
     return $this->hasMany(Media::className(), ['media_type' => 'id']);
 }
Exemplo n.º 19
0
 public function getvolumes($data = null)
 {
     $date = new Date('last ' . Input::get('date'));
     $volumes = Media::join($this->tables['pool'], $this->tables['media'] . '.poolid', '=', $this->tables['pool'] . '.poolid')->where('lastwritten', '>=', (string) $date)->select(array('volumename', 'slot', 'volbytes', 'mediatype', $this->tables['pool'] . '.name', 'lastwritten', 'volstatus'));
     return Datatables::of($volumes)->make();
 }
Exemplo n.º 20
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function publish($slug)
 {
     $news = Media::findBySlug($slug);
     $news->update(['is_published' => $news->is_published ? 0 : 1]);
     return Redirect::route('media.admin');
 }
Exemplo n.º 21
0
 public function setPhoto()
 {
     if (Auth::check()) {
         $text = Input::get('file');
         $destinationPath = 'images/users/';
         $data = $text['$ngfDataUrl'];
         list($type, $data) = explode(';', $data);
         list(, $type) = explode('/', $type);
         list(, $data) = explode(',', $data);
         $fileName = md5(date("YmdHis") . rand(5, 50)) . '.' . $type;
         $data = base64_decode($data);
         $media = Media::where('id', Auth::user()->media_id)->first();
         if (file_put_contents($destinationPath . $fileName, $data)) {
             if ($media->id != 1) {
                 $tmp = $media->name;
                 $media->name = URL::to('/') . "/" . $destinationPath . $fileName;
                 $media->save();
                 $arr = explode("/", $tmp);
                 unlink($destinationPath . $arr[count($arr) - 1]);
             } else {
                 $media = new Media();
                 $media->name = URL::to('/') . "/" . $destinationPath . $fileName;
                 $media->save();
                 $user = Auth::user();
                 $user->media_id = $media->id;
                 $user->save();
             }
             return $this->getProfile();
         } else {
             return response()->json(['result' => 'error'], 200);
         }
     } else {
         return response()->json(['result' => 'error'], 200);
     }
 }