/** * Migrate the images * * param int $product_id * param string $images */ private function _migrateImages($product_id, $images) { Citruscart::load('CitruscartImage', 'library.image'); foreach ($images->children() as $image) { $check = false; $multiple = false; $image = (string) $image; if (JURI::isInternal($image)) { $internal = true; $int_image = JPATH_SITE . DIRECTORY_SEPARATOR . $image; if (is_dir($int_image)) { $check = JFolder::exists($int_image); $multiple = true; } else { $check = JFile::exists($int_image); } // Now check the extracted images path if (!$check) { $dir = $this->_temp_dir . DIRECTORY_SEPARATOR . 'images' . DS; if (is_dir($dir . $image)) { $check = JFolder::exists($dir . $image); $multiple = true; } else { $check = JFile::exists($dir . $image); } if ($check) { $image = $dir . $image; } } else { $image = $int_image; } } else { $internal = false; $check = $this->url_exists($image); } // Add a single image if (!$multiple) { $images_to_copy = array($image); } else { // Fetch the images from the folder and add them $images_to_copy = Citruscart::getClass("CitruscartHelperProduct", 'helpers.product')->getGalleryImages($image); foreach ($images_to_copy as &$i) { $i = $image . DIRECTORY_SEPARATOR . $i; } } if ($check) { foreach ($images_to_copy as $image_to_copy) { if ($internal) { $img = new CitruscartImage($image_to_copy); } else { $tmp_path = JFactory::getApplication()->getCfg('tmp_path'); $file = fopen($image_to_copy, 'r'); $file_content = stream_get_contents($file); fclose($file); $file = fopen($tmp_path . DIRECTORY_SEPARATOR . $image_to_copy, 'w'); fwrite($file, $file_content); fclose($file); $img = new CitruscartImage($tmp_path . DIRECTORY_SEPARATOR . $image_to_copy); } Citruscart::load('CitruscartTableProducts', 'tables.products'); $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($product_id); $path = $product->getImagePath(); $type = $img->getExtension(); $img->load(); $img->setDirectory($path); // Save full Image $img->save($path . $img->getPhysicalName()); // Save Thumb Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); $imgHelper->resizeImage($img, 'product'); } } } }
private function _migrateImages($prefix = 'jos_', $vm_prefix = 'vm_', &$results, $internal = true) { $p = $prefix . $vm_prefix; // Fetch the VM full image if ($internal) { $db = JFactory::getDBO(); } else { $db = $this->_verifyDB(); } $query = "SELECT product_id as id, product_full_image as image FROM {$p}product"; $db->setQuery($query); $products = $db->loadAssocList(); Citruscart::load('CitruscartImage', 'library.image'); if ($internal) { $vm_image_path = JPATH_SITE . "/components/com_virtuemart/shop_image/product/"; } else { $state = $this->_getState(); $url = $state->external_site_url; $vm_image_path = $url . "/components/com_virtuemart/shop_image/product/"; } $n = count($results); $results[$n]->title = 'Product Images'; $results[$n]->query = 'Copy Product Images & Resize'; $results[$n]->error = ''; $results[$n]->affectedRows = 0; foreach ($products as $result) { $check = false; if ($internal) { $check = JFile::exists($vm_image_path . $result['image']); } else { $check = $this->url_exists($vm_image_path) && $result['image']; } if ($check) { if ($internal) { $img = new CitruscartImage($vm_image_path . $result['image']); } else { $tmp_path = JFactory::getApplication()->getCfg('tmp_path'); $file = fopen($vm_image_path . $result['image'], 'r'); $file_content = stream_get_contents($file); fclose($file); $file = fopen($tmp_path . DIRECTORY_SEPARATOR . $result['image'], 'w'); fwrite($file, $file_content); fclose($file); $img = new CitruscartImage($tmp_path . DS . $result['image']); } Citruscart::load('CitruscartTableProducts', 'tables.products'); $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($result['id']); $path = $product->getImagePath(); $type = $img->getExtension(); $img->load(); $name = $img->getPhysicalName(); // Save full Image if (!$img->save($path . $name)) { $results[$n]->error .= '::Could not Save Product Image- From: ' . $vm_image_path . $result['image'] . ' To: ' . $path . $result['image']; } $img->setDirectory($path); // Save Thumb Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); if (!$imgHelper->resizeImage($img, 'product')) { $results[$n]->error .= '::Could not Save Product Thumb'; } // Save correct image naming $product->product_full_image = $name; $product->save(); $results[$n]->affectedRows++; } } $n++; // CATEGORIES // Fetch the VM full image $query = "SELECT category_id as id, category_full_image as image FROM {$p}category"; $db->setQuery($query); $products = $db->loadAssocList(); Citruscart::load('CitruscartImage', 'library.image'); if ($internal) { $vm_image_path = JPATH_SITE . "/components/com_virtuemart/shop_image/category/"; } else { $state = $this->_getState(); $url = $state->external_site_url; $vm_image_path = $url . "/components/com_virtuemart/shop_image/category/"; } $results[$n]->title = 'Category Images'; $results[$n]->query = 'Copy Category Images & Resize'; $results[$n]->error = ''; $results[$n]->affectedRows = 0; foreach ($products as $result) { $check = false; if ($internal) { $check = JFile::exists($vm_image_path . $result['image']); } else { $check = $this->url_exists($vm_image_path) && $result['image']; } if ($check) { if ($internal) { $img = new CitruscartImage($vm_image_path . $result['image']); } else { $tmp_path = JFactory::getApplication()->getCfg('tmp_path'); $file = fopen($vm_image_path . $result['image'], 'r'); $file_content = stream_get_contents($file); fclose($file); $file = fopen($tmp_path . DS . $result['image'], 'w'); fwrite($file, $file_content); fclose($file); $img = new CitruscartImage($tmp_path . DS . $result['image']); } $img->load(); $path = Citruscart::getPath('categories_images') . DS; $name = $img->getPhysicalName(); // Save full Image if (!$img->save($path . $name)) { $results[$n]->error .= '::Could not Save Category Image - From: ' . $vm_image_path . $result['image'] . ' To: ' . $path . $result['image']; } $img->setDirectory($path); // Save Thumb Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); if (!$imgHelper->resizeImage($img, 'category')) { $results[$n]->error .= '::Could not Save Category Thumb'; } // Save correct image name Citruscart::load('CitruscartTableCategories', 'tables.categories'); $category = JTable::getInstance('Categories', 'CitruscartTable'); $category->load($result['id']); $category->category_full_image = $name; $category->save(); $results[$n]->affectedRows++; } } }