/**
  * Run the migrations.
  * Upgrade images table from Redminportal 0.1 to 0.2/0.3
  *
  * @return void
  */
 public function up()
 {
     // Check if the images table exists
     if (Schema::hasTable('images')) {
         if (Schema::hasColumn('images', 'imageable_type')) {
             $images = DB::select('select * from images');
             foreach ($images as $image) {
                 // Get the model name
                 $new_type_array = explode('\\', $image->imageable_type);
                 $last_model = array_pop($new_type_array);
                 // Move image to new folder
                 $image_folder = Config::get('redminportal::image.upload_dir');
                 switch ($last_model) {
                     case 'Category':
                         $move_file = $this->moveFileNewToOld($image_folder, $image, 'categories');
                         break;
                     case 'Media':
                         $move_file = $this->moveFileNewToOld($image_folder, $image, 'medias');
                         break;
                     case 'Module':
                         $move_file = $this->moveFileNewToOld($image_folder, $image, 'modules');
                         break;
                     case 'Promotion':
                         $move_file = $this->moveFileNewToOld($image_folder, $image, 'promotions');
                         break;
                     default:
                         $move_file = false;
                         break;
                 }
                 // Create dimensions
                 if ($move_file) {
                     $img_helper = new RImage();
                     $img_helper->createDimensions($move_file);
                 }
                 // Points to new namespace Redooor\\Redminportal\\App\\Models\\
                 $new_type = 'Redooor\\Redminportal\\App\\Models\\' . $last_model;
                 DB::table('images')->where('id', $image->id)->update(['imageable_type' => $new_type, 'path' => $move_file ? $move_file : $image->path]);
             }
         }
     }
 }