Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

php[architect]:
Exporting Drupal Nodes with PHP and Drush
Oct 06, 2015 @ 16:09:11

The php[architect] site has posted a tutorial showing you how to export Drupal nodes with Drush and a bit of regular PHP. Drush is a command line tool that makes working with Drupal outside of the interface simpler and easier to automate.

Drupal 8 development has shown that PHP itself, and the wider PHP community, already provides ways to solve common tasks. In this post, I’ll show you some core PHP functionality that you may not be aware of; pulling in packages and libraries via Composer is a topic for another day.

The tutorial walks through a more real-world situation of needing to export a CSV file that shows a list of nodes added to the site after a specific date. He points out some of the benefits of doing it the Drush way and starts in on the code/configuration you need to set the system up. He shows how to create the Drush command itself and update it with a method to export the newest nodes (after validating the date provided). He makes use of a SplFileObject to output the results from the EntityFieldQuery query out into to the CSV file. He makes use of PHP's generators functionality to only fetch the records a few at a time. Finally he includes the command to execute the export, defining the date to query the node set and how to push that output to a file.

tagged: export drupal node drush commmandline csv output query generator

Link: https://www.phparch.com/2015/10/exporting-drupal-nodes-with-php-and-drush/

Proof Group's Blog:
Know Your PHP Environments
Dec 09, 2009 @ 19:10:17

On the Proof Group's blog there's a recent post about a "gotcha" Andy Chase found when using the Drush command line tool for Drupal installations and a system that has MAMP installed.

Recently, however, I installed MAMP to debug some older, PHP4-specific code. [...] I also use Drush, which is an indispensable Drupal command line tool, and I began getting the following error on some sites: Drush command could not be completed.

This only caused a problem when he went back to his previous PHP5-based installation. He finally found the culprit - a section of the Drush script that looked for MAMP installs and tried to use those binaries and configuration files (the PHP4 ones) instead of his more correct PHP5 ones. A quick commenting later everything worked fine.

tagged: environment mamp drush drupal

Link:


Trending Topics: