Image disappears if amending existing image

Report issues with Enuuk Auction Platform or Mods here - remember to raise a ticket with phpauction.net as well
Post Reply
RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Image disappears if amending existing image

Post by RWAP » Wed Jul 31, 2013 8:33 am

When editing an existing listing, if the user clicks on remove image (eg the default image) and then uploads an image of the same name (for example, if they have edited the original image on their PC), they can end up with a blank image for their listing!

This can be addressed by the following changes to class\Action\Offer.php -> processOfferForm()

Find:

Code: Select all

            // default image for item
            if($_FILES['defaultImage']['name']){
                $overwrite = ($par['action'] != 'add');
Add below this:

Code: Select all

                if ($overwrite) $deleteOldImage=$par['defaultImageOld'];
Then find:

Code: Select all

            foreach($images as $image){
                if($image instanceof Image){
                    if($image->saveToDB($this->db)){
                        $item->addImage($image);
                    }
                }
            }

            $item->saveToDB($this->db);
Add after this add:

Code: Select all

			if ($deleteOldImage) {
				$par['removeDefault']=false;
                $img = Image::getInstanceFromDB($this->db,$deleteOldImage);
				if($img instanceof Image){
					$img->deleteFromDB($this->db);
				}
			}
(This is actually missing from the current Enuuk platform and as a result, the original default image for a listing was left if you simply uploaded a replacement).

Find:

Code: Select all

                    if($par['action'] == 'modify'){
                        if(count($oldImage)){
                            foreach($oldImage as $k=>$img){
                                if($img instanceof Image){
                                $img->deletefromDB($this->db);
                                }
                            }
                        }
                        if(count($oldImg)){
                            foreach($oldImg as $k=>$img){
                                if($img instanceof Image){
                                $img->deletefromDBOnly($this->db);
                                }
                            }
                        }

                        //removing the images selected for removal
                        if(isset($par['imageToRemove'])){
                            foreach($par['imageToRemove'] as $imgID){
                                $img = Image::getInstanceFromDB($this->db,$imgID);
                                if($img instanceof Image){
                                    $img->deleteFromDB($this->db);
                                }
                            }
                        }
Change this to:

Code: Select all

                    if($par['action'] == 'modify'){
                        $deletedImages=array();
                        if(count($oldImage)){
                            foreach($oldImage as $k=>$img){
                                if($img instanceof Image){
                                	$deletedImages[]=$img->id;
                                    $img->deletefromDB($this->db);
                                }
                            }
                        }
                        if(count($oldImg)){
                            foreach($oldImg as $k=>$img){
                                if($img instanceof Image){
                                	$deletedImages[]=$img->id;
                                    $img->deletefromDBOnly($this->db);
                                }
                            }
                        }

                        //removing the images selected for removal
                        if(isset($par['imageToRemove'])){
                            foreach($par['imageToRemove'] as $imgID){
                                if (!in_array($imgID,$deletedImages)) {
	                                $img = Image::getInstanceFromDB($this->db,$imgID);
	                                if($img instanceof Image){
	                                    $img->deleteFromDB($this->db);
	                                }
                                }
                            }
                        }

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest