VirtueMart Forum

VirtueMart 2 + 3 + 4 => Installation, Migration & Upgrade => Topic started by: AH on July 18, 2013, 21:35:29 PM

Title: Image - media data migration errors
Post by: AH on July 18, 2013, 21:35:29 PM
Migrating images causes the new images to have very poor titles and alts stored

These are then used in displays!  Not so good.

Without these

Line 395
Still not happy about the filename being the file_title

Has anyone actually checked what a poor result this gives??



'file_title' => $file['filename'],
    'virtuemart_vendor_id' => 1,
//quorvia change
//     'file_description' => $file['filename'],
//     'file_meta' => $file['filename'],
'file_description' = "",
'file_meta' = "",    
//quorvia end   




Note if you do this the default_images.php will not show an alt attribute (v.bad)

At least if the file_meta (alt) and file_title (title) is not available the product name should be used?



jQuery(".additional-images .product-image").click(function() {
jQuery(".main-image img").attr("src",this.src );
jQuery(".main-image img").attr("alt",this.alt );
jQuery(".main-image a").attr("href",this.src );
jQuery(".main-image a").attr("title",this.alt );
});



Title: Re: Image - media data migration errors
Post by: mbarry on January 28, 2014, 15:12:58 PM
Agree assigning filenames results in unreadable titles and alt text.

My solution was to populate the file_description and file_meta entries with the associated category and product names during the portCategory() and portProduct() migration process

administrator/components/com_virtuemart/helpers/migrator.php

For portCategory()

                                $catModel->setId(0);
$category_id = $catModel->store($category);
$errors = $catModel->getErrors();
if(!empty($errors)){
foreach($errors as $error){
vmError('Migrator portCategories '.$error);
$ok = false;
}
break;
}
// Add these lines
if(!empty($category['virtuemart_media_id'])) {
$this->_setMediaAttributes($category['virtuemart_media_id'], $category['category_name'], 'category');
                                }


For portProduct()

if(!empty($errors)){
foreach($errors as $error){
vmError('Migration: '.$i.' ' . $error);
}
vmdebug('Product add error',$product);
$productModel->resetErrors();
$continue = false;
break;
}
// Add these lines
if(!empty($product['virtuemart_media_id'])) {
$this->_setMediaAttributes($product['virtuemart_media_id'], $product['product_name'], 'product');
}



Create this new function

/**
* Sets the Media attributes file_description and file_meta based on the provided medianame
* These fields don't exist in VM1 so we use the category, product or vendor name instead
*
* @author M. Barry
*
*/
function _setMediaAttributes($mediaId, $mediaName, $type) {

$mediaName = $this->_db->getEscaped($mediaName);

$q = 'UPDATE `#__virtuemart_medias` SET `file_description`="'.$mediaName.'", `file_meta`="'.$mediaName.'" WHERE `virtuemart_media_id` = "'.$mediaId.'" AND `file_type`="'.$type.'"';

$this->_db->setQuery($q);
if(!$this->_db->query()){
$this->_app->enqueueMessage('set Media Attributes failed to update query '.$this->_db->getQuery());
$this->_app->enqueueMessage('and ErrrorMsg '.$this->_db->getErrorMsg());
}
}



This could be extended for Manufacturer and Vendor Images as well.

Title: Re: Image - media data migration errors
Post by: AH on January 28, 2014, 17:11:27 PM
Mbarry

I decided to leave the data alone in the migration and manipulate the image.php

If there is data, it uses it, otherwise it uses the item description  saves having to key it in during product creation.. That can be a real pain especially if you decide to change description and forget the ALT
Title: Re: Image - media data migration errors
Post by: mbarry on January 29, 2014, 14:10:21 PM
Good point. I can certainly see benefits of populating this at run-time using product or category names.