Masse delete not fudet images

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #195151

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4
-- PHP version -- : 5.6.6
-- Browser(s) name and version -- : www.dcom.dk

Hello everyone
I was wondering if there is a function that can erase images which are not found or is damaged.

The reason I spøre into this is my sides have over 13000 products which are blver import with cvs but part of the bill shoulder does not look like it worked so I am to have found a way to find all the pictures that do not work on my since then it becomes clear again, that I may be new pictures up.

any good ideas?

Theis

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #195159

Hi,

There is not functions like that by default in HikaShop.
It will require a custom script.

What could potentially be done, is to export all the products in csv via the mass actions with only the images informations.
Then thanks to the custom script, look over all the images, and if they are not in the csv file so delete them.
It require good PHP knowledges.

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #195334

Yes it is probably easiest to take it in the database or cvs.
But do you think it is possible to get Hika system to brands the picture where the user defult picture on the database?
With a piece of text or something

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #195343

Hi,

Sorry but I don't really understand your question.

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #195542

You know when hikashop can not find the picture inserts the default picture.

If you look at this product,
www.dcom.dk/p/149513-
There are errors in the first image when image can not be found or it is broken.

If you could get hikashop every time it use the default picture to also deleted these images every time it can not be found or is damaged from File_paht then it would be easy for me to see which of my 13000 product does not have a real picture that works :whistle:

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #195546

Hi,

If HikaShop take the default picture that's because it can't find the image on the server, so we can't delete it as we don't know the path. But if you are talking about the entry in the database, yes, that could be a good thing.

I add it on our Todo list. :)

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #195870

super :)

but do you have a ide to what files i shall look in to ? to try to fix this problem :)

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #195871

Hi,

I think that the best place will be in the image helper: "administrator/components/com_hikashop/helpers/image.php" in the function "_checkImage()".
This function only check if the image exists, so if it is not the case, you could potentially delete the entry in the "#__hikashop_file" table.

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #195973

Oh nice i will start to work on it an tun back when i kohw somting ore need more help :)

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #195984

Hi,

You can replace the function with that code:

	function _checkImage($path){
		if(!empty($path)){
			jimport('joomla.filesystem.file');
			if(JFile::exists($path)){
				return true;
			}
			$db = JFactory::getDBO();
			$query = 'DELETE FROM '.hikashop_table('file').' WHERE file_path = \''.$db->quote($path).'\' AND file_type=\'product\'';
			$db->setQuery($query);
			$db->query();
		}
		return false;
	}

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #196011

Okay i will look in to it tanks :)

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #196015

i tink it works at soon i know what to do with it´s error i get a error on line 423 that i do get.

Parse error: syntax error, unexpected 'path' (T_STRING) in /media/mynewdrive/html/Dcom3.0/administrator/components/com_hikashop/helpers/image.php on line 423

any idea :)

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #196016

Please try that code instead:

function _checkImage($path){
		if(!empty($path)){
			jimport('joomla.filesystem.file');
			if(JFile::exists($path)){
				return true;
			}
			$db = JFactory::getDBO();
			$query = 'DELETE FROM '.hikashop_table('file').' WHERE file_path = '.$db->quote($path).' AND file_type=\'product\'';
			$db->setQuery($query);
			$db->query();
		}
		return false;
	}

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #196044

okey no error but also notings happen after i put the lines in.
Hmm what are we misssing

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #196135

Cut it has somting to do with i´am ursning joomla 3,4

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #196141

Hi,

A better solution, because easily customizable, and no code lost when updating will be to edit the view "product / show_block_img" via the menu Display > Views in HikaShop and at the top at the file add this code:

<?php
	if(!empty ($this->element->images)){
		$image = reset($this->element->images);
	}
	if(isset($image->file_path) && !empty($image->file_path)){
		$config = hikashop_config();
		$uploadFolder = ltrim(JPath::clean(html_entity_decode($config->get('uploadfolder'))),DS);
		$uploadFolder = rtrim($uploadFolder,DS).DS;
		$uploadFolder_url = str_replace(DS,'/',$uploadFolder);
		$uploadFolder = JPATH_ROOT.DS.$uploadFolder;
		$fullPath = $uploadFolder.$image->file_path;
		if(!JFile::exists($fullPath)) {
			$db = JFactory::getDBO();
			$query = 'DELETE FROM '.hikashop_table('file').' WHERE file_path = '.$db->quote($image->file_path).' AND file_type=\'product\'';
			$db->setQuery($query);
			$db->query();
		}
	}
?>

The following user(s) said Thank You: Jerome

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #196204

Yes it works :cheer:

Tanks you are lifesaver now it is easy to see what product the are missing images

You save me a lot off time

Theis

Last edit: 10 years 2 months ago by the heatkiller.

Please Log in or Create an account to join the conversation.

Time to create page: 0.117 seconds
Powered by Kunena Forum