/** * Will consolidate a product's images into its currently set path. * If an image already exists in the current path with the same name, * will either leave the iamge in the old path or delete it if delete_duplicates = true * * @param $row Tienda Product * @param $delete_duplicates * @return unknown_type */ function consolidateGalleryImages($row, $delete_duplicates = false) { $file_moved = null; // get the current path for the product $path = $this->getGalleryPath($row); // get the current list of images in the current path $images = $this->getGalleryImages($path, array(), false); // if there are any images in the other possible paths for the product, move them to the current path $dir = Tienda::getPath('products_images'); // merge the SKU-based dir if it exists and isn't the current path if (!empty($row->product_sku) && $this->checkDirectory($dir . '/' . $row->product_sku, false) && $dir . '/' . $row->product_sku . '/' != $path) { $old_dir = $dir . '/' . $row->product_sku . '/'; $files = JFolder::files($old_dir); foreach ($files as $file) { if (!in_array($file, $images)) { if (JFile::move($old_dir . $file, $path . $file)) { // create new thumb too Tienda::load('TiendaImage', 'library.image'); $img = new TiendaImage($path . $file); $img->setDirectory($path); Tienda::load('TiendaHelperImage', 'helpers.image'); $imgHelper = TiendaHelperBase::getInstance('Image', 'TiendaHelper'); $imgHelper->resizeImage($img); // delete old thumb JFile::delete($old_dir . 'thumbs/' . $file); $file_moved = true; } } else { // delete the old one? if ($delete_duplicates) { JFile::delete($old_dir . $file); } } } } else { $subdirs = TiendaHelperProduct::getSha1Subfolders($row->product_sku); // merge the SKU-based SHA1 dir if it exists and isn't the current path if (!empty($row->product_sku) && $this->checkDirectory($dir . '/' . $subdirs . $row->product_sku, false) && $dir . '/' . $subdirs . $row->product_sku . '/' != $path) { $old_dir = $dir . '/' . $subdirs . $row->product_sku . '/'; $files = JFolder::files($old_dir); foreach ($files as $file) { if (!in_array($file, $images)) { if (JFile::move($old_dir . $file, $path . $file)) { // create new thumb too Tienda::load('TiendaImage', 'library.image'); $img = new TiendaImage($path . $file); $img->setDirectory($path); Tienda::load('TiendaHelperImage', 'helpers.image'); $imgHelper = TiendaHelperBase::getInstance('Image', 'TiendaHelper'); $imgHelper->resizeImage($img); // delete old thumb JFile::delete($old_dir . 'thumbs' . '/' . $file); $file_moved = true; } } else { // delete the old one? if ($delete_duplicates) { JFile::delete($old_dir . $file); } } } } } // merge the ID-based dir if it exists and isn't the current path if ($this->checkDirectory($dir . '/' . $row->product_id, false) && $dir . '/' . $row->product_id . '/' != $path) { $old_dir = $dir . '/' . $row->product_id . '/'; $files = JFolder::files($old_dir); foreach ($files as $file) { if (!in_array($file, $images)) { if (JFile::move($old_dir . $file, $path . $file)) { // create new thumb too Tienda::load('TiendaImage', 'library.image'); $img = new TiendaImage($path . $file); $img->setDirectory($path); Tienda::load('TiendaHelperImage', 'helpers.image'); $imgHelper = TiendaHelperBase::getInstance('Image', 'TiendaHelper'); $imgHelper->resizeImage($img); // delete old thumb JFile::delete($old_dir . 'thumbs' . '/' . $file); $file_moved = true; } } else { // delete the old one? if ($delete_duplicates) { JFile::delete($old_dir . $file); } } } } else { $subdirs = TiendaHelperProduct::getSha1Subfolders($row->product_id); // merge the ID-based SHA1 dir if it exists and isn't the current path if ($this->checkDirectory($dir . '/' . $subdirs . $row->product_id, false) && $dir . '/' . $subdirs . $row->product_id . '/' != $path) { $old_dir = $dir . '/' . $subdirs . $row->product_id . '/'; $files = JFolder::files($old_dir); foreach ($files as $file) { if (!in_array($file, $images)) { if (JFile::move($old_dir . $file, $path . $file)) { // create new thumb too Tienda::load('TiendaImage', 'library.image'); $img = new TiendaImage($path . $file); $img->setDirectory($path); Tienda::load('TiendaHelperImage', 'helpers.image'); $imgHelper = TiendaHelperBase::getInstance('Image', 'TiendaHelper'); $imgHelper->resizeImage($img); // delete old thumb JFile::delete($old_dir . 'thumbs/' . $file); $file_moved = true; } } else { // delete the old one? if ($delete_duplicates) { JFile::delete($old_dir . $file); } } } } } return $file_moved; }