I'm having a time migrating images from Wordpress to Drupal with the Migrate 2.4 module. Here are my mappings:
$this->addFieldMapping('field_image','images');
$this->addFieldMapping('destination_file', 'images');
$this->addFieldMapping('field_image:source_dir')
->defaultValue('/Users/grafa/htdocs/wordpress/wp-content/uploads');
$this->addFieldMapping('field_image:file_class')
->defaultValue('MigrateFileUri');
The images come from a function that queries the wp_postmeta table then returns the result to the prepareRow() function.
function getImages($row) {
$post_id = $row->id;
$results = db_query("
SELECT pm.post_id, pm.meta_key, pm.meta_value FROM streetroots_wp.wp_postmeta AS pm LEFT JOIN streetroots_wp.wp_posts AS p ON pm.post_id=p.id WHERE p.post_parent = $post_id AND pm.meta_key='_wp_attached_file';");
$images = array();
foreach($results as $result) {
$images[] = $result->meta_value;
}
return !empty($images) ? $images : NULL;
}
This basically returns the image name and relative path from the wp_postmeta table something like '2012/05/figure1.jpg'. I then use prepareRow() like this:
function prepareRow($row) {
$row->images = $this->getImages($row);
}
I'm guessing there's something funky with how I'm using the new-ish migrate module that handles the file fields. The sql is outputs the file names correctly but it doesn't seem like the images are getting copied over. This is a Drupal 7 using Migrate 2.4. Any help is appreciated.
You might want to have a look at the beer.inc lines 377 - 383 within migrate_example folder and at the associated content type *migrate_example_beer* which has an image field defined not a file field which was my mistake and lead to my images not being populated.
Hope this helps!
Migrate 2.5 has largely simplified the handling of files, you should check it out!
Related
I have a program that can print an individual PDF when on a students file. I'm doing this using niklasravnsborg/laravel-pdf package in Laravel 5.7. It's working great because I can just stream the pdf from a view into the browser then print from there.
Now I'm wanting to batch print the PDF's at the end of the day instead of one by one. How can I do this? There's no documentation for this on the package repository.
Several ways I've thought of doing this: one, save each PDF as an image file then try to print all files in that folder at the end of the day. If I do this, how would I print all files in that folder?
Next: does anyone know a way to maybe append a new PDF to a variable containing all the previously looped pdf's?
For example:
$finalpdf;
$students = Student::all();
foreach($students as $student){
$pdf = PDF::loadView('pdf.document', $student);
$finalpdf .+ $pdf; //i know this line doesn't work, but how to alter it?
return $pdf->save('document.pdf');
}
After a few days of playing around, hopefully this solution helps someone in the future. I used another package called "lara pdf merger". By writing my files to a save destination, adding those files to a merged file, then deleting the saved files after download, I was able to get my functionality. This is my controller code:
use PDF;
use Illuminate\Filesystem\Filesystem;
use LynX39\LaraPdfMerger\Facades\PdfMerger;
public function batchPrint(){
$pdfMerger = PDFMerger::init();
$i = 0;
$students = Student::whereDate('updated_at', Carbon::today('America/Los_Angeles'))->get();
foreach ($students as $student) {
$pdf = PDF::loadView('printTables', compact('student'));
$pdf->save('pdf/document'.$i.'.pdf');
$pdfMerger->addPDF('pdf/document'.$i.'.pdf');
$i++;
}
$pdfMerger->merge();
$pdfMerger->save("file_name.pdf", "browser");
$file = new Filesystem;
$file->cleanDirectory('pdf');
}
I've installed Carrot2 on a web application (PHP language). Everything works perfectly. Now i want to change the language of my results. I want to change english for french. I search on carrot2 documentation, on the web but i didn't find what i want (this link was usefull but it seems like the dcs folder had change since this post http://carrot2-users-and-developers-forum.607571.n2.nabble.com/Change-Language-in-DCS-REST-PHP-td639270.html). Anyway, i pass my paramaters (algo, query, source, etc.) with a simple form (and differents variables) and send them (PHP) to carrot2's method with curl. I tried different (strange or barbaric) ways to send french language :
$language = 'lang_fr'; // or $language = 'FRENCH'
$num = (isset($_GET["maxResult"])) ? $_GET["maxResult"] : "10";
$query = urlencode($_GET["query"]);
$source = "web";
$algorithm = "lingo";
$hierarchy = "max-hierarchy-depth";
$level_hierarchie= $_GET["deep"] ? $_GET["deep"] : "1";
$processor = new Carrot2Processor();
$job = new Carrot2Job();
$job->setSource($source);
$job->setQuery($query);
$job->setAlgorithm($algorithm);
$job->setAttribute("results", $num);
$job->setAttribute($hierarchy, $level_hierarchie);
i tried to set language like this in the setAttribute() funtion and of course it doesn't work.
$job->setAttribute("language", $language);
try {
$result = $processor->cluster($job);
} catch (Carrot2Exception $e) {
echo 'An error occurred during processing: ' . $e->getMessage();
exit(10);
}
I Also tried to change the CURLOPT_HTTPHEADER(add 'Accept-langugage: fr').
I see different responses but only for developpers using java and im using php. Is it possible to pass language choice with the setAttribute() method on PHP? Someone knows a way to do that?
Thank you in advance (i use carrot2-dcs-3.16)
For the eTools meta search engine, you can set the EToolsDocumentSource.language attribute directly in your calling code:
$job->setAttribute("EToolsDocumentSource.language", "FRENCH");
See the attribute documentation linked above for the list of supported languages.
So I'm just trying to use xeditable (http://vitalets.github.io/x-editable/docs.html#gettingstarted) to make changes to my database via AJAX.
Since I'm new to this concept and I'm (forcefully) working with PHP for the first time, I need some help.
I setup the frontend part, and a script called (say) script.php is handling the data for me (I need to write the new value in my database).
I can't really understand what to do in the script. Can someone guide me towards it? The docs above don't really do it for me.
Looking in a project I worked on a few months back (sorry about the mysql_ stuff – not my choice!)
Something like:
<?
include your/database/connection_stuff.php;
// Can't remember if x-editable passes the table in as well or not
$table = mysql_real_escape_string($_GET['table']);
// If not,
$table = 'name_of_table';
$value = mysql_real_escape_string($_POST['value']);
$name = mysql_real_escape_string($_POST['name']);
$pk = mysql_real_escape_string($_POST['pk']);
$result = mysql_query("UPDATE `$table` SET `$name` = '$value' WHERE id = '$pk'");
?>
Will do the trick.
I'm new to smarty and prestashop. I'm building a quick, dirty module that pulls out cms pages with a particular category:
$result = Db::getInstance()->executeS('SELECT *
FROM ps_cms_lang
INNER JOIN ps_cms ON ps_cms_lang.id_cms = ps_cms.id_cms
WHERE ps_cms.id_cms_category =2
AND id_lang =1
LIMIT 0 , 30');
$smarty->assign('news', $result);
So far this is all working dandy. Thing is I want to format some of this data before I assign it to the template variable (news). How do I do this? 6 fields are returned in the $result variable. How do I get at them and do what I need (which is essentially just truncating some of the text in the description field that is returned) to do and then package them back up for the assign?
You may use $result as array, for example: $result['id_cms'].
I am using Magento 1.5.0.1 and the getProductUrl() function used in the cross sell and up sell blocks on the product page is throwing up different URL formats.
Either the correct url like:
/laptop-bag.html
Or the wrong one (well it works, but of course its not the rewrite URL):
/catalog/product/view/id/825/s/laptop-bag/category/16/
Sometimes both cross sell and up sell blocks return the correct URL, sometimes both use the longer version, and in some cases, one uses the correct and the other uses the long version??
Any ideas why this is happening?
I have already run a magento database repair, reindexed, and refreshes / flushed all caches.
Try $product->getUrlPath() instead of $product->getProductUrl()
UPDATE: As per below comment by #jordan314, Magento recommends to EE customers:
The url_path attribute is no longer used as of 1.13 but is still available for backward-compatibility, and Magento will not assign a value to it for new products, so it's not recommended to continue using it. Perhaps you could try using $product->getProductUrl() instead.
The incorrect url is generated because it can't find the rewritten url.
Maybe it is caused because incorrect store_id.
eg:
$id = 290;
Mage::app()->setCurrentStore('default');
echo "store_id: ".Mage::app()->getStore()->getId()."<br>";
$url = Mage::helper('catalog/product')->getProductUrl($id);
echo $url."<br>";
//change store id
Mage::app()->setCurrentStore('admin');
echo "store_id: ".Mage::app()->getStore()->getId()."<br>";
$url = Mage::helper('catalog/product')->getProductUrl($id);
echo $url."<br>";
result:
store_id: 1
http://local.com/surestep-pro-diabetic-test-strips-50-strips-professional-care.html
store_id: 0
https://local.com/index.php/catalog/product/view/id/290/s/surestep-pro-diabetic-test-strips-50-strips-professional-care/
The correct url rewrite can be found in table named core_url_rewrite (including the information about the store_id)
If it found match value in core_url_rewrite, it will generate 'the correct url' else it will concat the product_id + url key + category_id
$routePath = 'catalog/product/view';
$routeParams['id'] = $product->getId();
$routeParams['s'] = $product->getUrlKey();
if ($categoryId) {
$routeParams['category'] = $categoryId;
}
Try add this when you're getting your collection
$collection->addUrlRewrite();
It has helped me.
$id = 10;
Mage::app()->setCurrentStore('admin');
$url = Mage::helper('catalog/product')->getProductUrl($id);