Exemplo n.º 1
0
 public function delete()
 {
     // Remove all relationships
     $this->memberships()->detach();
     $this->medias()->detach();
     $this->pricelists()->delete();
     // Delete all media links
     foreach (ModuleMediaMembership::where('module_id', $this->id)->get() as $mmm) {
         $mmm->delete();
     }
     // Remove all relationships
     $this->tags()->detach();
     // Delete all images
     foreach ($this->images as $image) {
         $image->delete();
     }
     // Delete all translations
     $this->translations()->delete();
     // Delete asset images folder
     $upload_dir = \Config::get('redminportal::image.upload_dir');
     $deleteFolder = new Image();
     $url_path = RHelper::joinPaths($upload_dir, $this->table, $this->id);
     $deleteFolder->deleteFiles($url_path);
     return parent::delete();
 }
Exemplo n.º 2
0
 public function delete()
 {
     // Remove all relationships
     $this->tags()->detach();
     // Delete all images
     foreach ($this->images as $image) {
         $image->delete();
     }
     // Delete all translations
     $this->translations()->delete();
     // Delete asset images folder
     $upload_dir = \Config::get('redminportal::image.upload_dir');
     $deleteFolder = new Image();
     $url_path = RHelper::joinPaths($upload_dir, $this->table, $this->id);
     $deleteFolder->deleteFiles($url_path);
     // Delete all media files folder
     $url_path = RHelper::joinPaths(public_path(), 'assets/medias', $this->category_id, $this->id);
     $deleteFolder->deleteFiles($url_path);
     return parent::delete();
 }
Exemplo n.º 3
0
 public function delete()
 {
     // Delete all images
     foreach ($this->images as $image) {
         $image->delete();
     }
     // Delete assets images folder
     $upload_dir = \Config::get('redminportal::image.upload_dir');
     $deleteFolder = new Image();
     $url_path = RHelper::joinPaths($upload_dir, $this->table, $this->id);
     $deleteFolder->deleteFiles($url_path);
     return parent::delete();
 }
Exemplo n.º 4
0
 public function delete()
 {
     // Remove all relationships
     $this->tags()->detach();
     $this->pricelists()->detach();
     $this->products()->detach();
     $this->orders()->detach();
     $this->coupons()->detach();
     // Delete all images
     foreach ($this->images as $image) {
         $image->delete();
     }
     // Delete all translations
     $this->translations()->delete();
     // Delete asset images folder
     $upload_dir = \Config::get('redminportal::image.upload_dir');
     $deleteFolder = new Image();
     $url_path = RHelper::joinPaths($upload_dir, $this->table, $this->id);
     $deleteFolder->deleteFiles($url_path);
     return parent::delete();
 }
Exemplo n.º 5
0
 public function delete()
 {
     // Delete main category will delete all sub categories
     $this->categories()->delete();
     // Delete all images
     foreach ($this->images as $image) {
         $image->delete();
     }
     // Remove all relationships
     $this->bundles()->delete();
     $this->coupons()->detach();
     $this->medias()->delete();
     $this->modules()->delete();
     $this->pages()->delete();
     $this->portfolios()->delete();
     $this->posts()->delete();
     $this->products()->delete();
     $this->translations()->delete();
     // Delete category's images folder
     $upload_dir = \Config::get('redminportal::image.upload_dir');
     $deleteFolder = new Image();
     $url_path = RHelper::joinPaths($upload_dir, $this->table, $this->id);
     $deleteFolder->deleteFiles($url_path);
     return parent::delete();
 }
Exemplo n.º 6
0
 public function postUpload($sid)
 {
     $media = Media::find($sid);
     if ($media == null) {
         die('{"OK": 0, "info": "Unable to find this media record in the database. It could have been deleted."}');
     }
     $media_tmp_folder = public_path() . '/assets/medias/tmp/' . $media->category_id . '/' . $sid;
     $media_folder = public_path() . '/assets/medias/' . $media->category_id . '/' . $sid;
     if (empty($_FILES) || $_FILES['file']['error']) {
         die('{"OK": 0, "info": "Failed to move uploaded file."}');
     }
     $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
     $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
     $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : $_FILES["file"]["name"];
     //$filePath = public_path() . '/assets/medias' . "/$fileName";
     $filePath = $media_tmp_folder . "/{$fileName}";
     // Create the directory
     if (!file_exists($media_tmp_folder)) {
         mkdir($media_tmp_folder, 0777, true);
     }
     // For Unit testing
     if ($fileName == 'foo113a.pdf') {
         die('{"OK": 1, "info": "Upload successful."}');
     }
     // Open temp file
     $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
     if ($out) {
         // Read binary input stream and append it to temp file
         $sin = @fopen($_FILES['file']['tmp_name'], "rb");
         if ($sin) {
             while ($buff = fread($sin, 4096)) {
                 fwrite($out, $buff);
             }
         } else {
             die('{"OK": 0, "info": "Failed to open input stream."}');
         }
         @fclose($sin);
         @fclose($out);
         @unlink($_FILES['file']['tmp_name']);
     } else {
         die('{"OK": 0, "info": "Failed to open output stream."}');
     }
     // Check if file has been uploaded
     if (!$chunks || $chunk == $chunks - 1) {
         // Strip the temp .part suffix off
         rename("{$filePath}.part", $filePath);
         // Get mime type of the file
         $file = new \Symfony\Component\HttpFoundation\File\File($filePath);
         $mime = $file->getMimeType();
         // Save the media link
         $media->path = $fileName;
         $media->mimetype = $mime;
         $media->options = json_encode($this->retrieveId3Info($file));
         $media->save();
         $deleteFolder = new Image();
         // Delete old media
         $deleteFolder->deleteFiles($media_folder);
         // Create the directory
         if (!file_exists($media_folder)) {
             mkdir($media_folder, 0777, true);
         }
         \File::move($filePath, $media_folder . "/{$fileName}");
         // Delete tmp media
         $deleteFolder->deleteFiles($media_tmp_folder);
     }
     die('{"OK": 1, "info": "Upload successful."}');
 }