From f544c5f8b528348ac48b50d4a5f881c2aaf3e013 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 31 Jan 2019 13:29:31 -0700 Subject: [PATCH] Add ImportAvatar job --- app/Jobs/AvatarPipeline/ImportAvatar.php | 95 ++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 app/Jobs/AvatarPipeline/ImportAvatar.php diff --git a/app/Jobs/AvatarPipeline/ImportAvatar.php b/app/Jobs/AvatarPipeline/ImportAvatar.php new file mode 100644 index 00000000..19beb23a --- /dev/null +++ b/app/Jobs/AvatarPipeline/ImportAvatar.php @@ -0,0 +1,95 @@ +url = $url; + $this->profile = $profile; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $url = $this->url; + $profile = $this->profile; + + $basePath = $this->buildPath(); + } + + public function buildPath() + { + $baseDir = storage_path('app/public/avatars'); + if (!is_dir($baseDir)) { + mkdir($baseDir); + } + + $prefix = $this->profile->id; + $padded = str_pad($prefix, 12, 0, STR_PAD_LEFT); + $parts = str_split($padded, 3); + foreach ($parts as $k => $part) { + if ($k == 0) { + $prefix = storage_path('app/public/avatars/'.$parts[0]); + if (!is_dir($prefix)) { + mkdir($prefix); + } + } + if ($k == 1) { + $prefix = storage_path('app/public/avatars/'.$parts[0].'/'.$parts[1]); + if (!is_dir($prefix)) { + mkdir($prefix); + } + } + if ($k == 2) { + $prefix = storage_path('app/public/avatars/'.$parts[0].'/'.$parts[1].'/'.$parts[2]); + if (!is_dir($prefix)) { + mkdir($prefix); + } + } + if ($k == 3) { + $avatarpath = 'public/avatars/'.$parts[0].'/'.$parts[1].'/'.$parts[2].'/'.$parts[3]; + $prefix = storage_path('app/'.$avatarpath); + if (!is_dir($prefix)) { + mkdir($prefix); + } + } + } + $dir = storage_path('app/'.$avatarpath); + if (!is_dir($dir)) { + mkdir($dir); + } + $path = $avatarpath.'/avatar.svg'; + return storage_path('app/'.$path); + } +}