Created
April 13, 2012 02:12
-
-
Save jrbeeman/2372972 to your computer and use it in GitHub Desktop.
drupal feeds bulk import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
/** | |
* Utility a script that will loop through feed nodes of a given importer and, | |
* in a performant way, re-import them all. | |
* | |
* Usage: feeds-bulk-import @site-alias importer_name | |
*/ | |
// Make sure we have args | |
$alias = $argv[1]; | |
if (!$alias) { | |
print "An alias is required, e.g. `feeds-bulk-import @site.dev my_importer`\n"; | |
exit(); | |
} | |
$importer = htmlspecialchars($argv[2], ENT_QUOTES, 'UTF-8'); | |
if (!$importer) { | |
print "An importer is required, e.g. `feeds-bulk-import @site.dev my_importer`\n"; | |
exit(); | |
} | |
// Get the list of nodes to import | |
print "Generating list of feed nodes to import...\n"; | |
$nodes = array(); | |
$query = "SELECT feed_nid FROM feeds_source WHERE id = '$importer'"; | |
$cmd = 'drush '. $alias .' sql-query "'. $query .'"'; | |
$result = NULL; | |
exec($cmd, $result); | |
$nids = array(); | |
foreach ($result as $item) { | |
if (is_numeric($item)) { | |
$nids[$item] = $item; | |
} | |
} | |
if (empty($nids)) { | |
print("No feeds to refresh.\n"); | |
exit(); | |
} | |
// Run through each node and run the import | |
print("Refreshing ". count($nids) ." feeds\n"); | |
foreach ($nids as $nid) { | |
$cmd = 'drush '. $alias .' feeds-import '. $importer .' --nid='. $nid; | |
print("Running $cmd\n"); | |
system($cmd); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment