| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: migrate.drush.inc,v 1.1.2.10 2009/09/09 17:34:51 weitzman Exp $ 3 4 /** 5 * @file 6 * Drush support for the migrate module 7 */ 8 9 /** 10 * Implementation of hook_drush_help(). 11 */ 12 function migrate_drush_help($section) { 13 switch ($section) { 14 case 'drush:migrate all': 15 return dt('Run the full migration process'); 16 case 'drush:migrate clear': 17 return dt('Clear a given migration content set'); 18 case 'drush:migrate import': 19 return dt('Import a given migration content set'); 20 case 'drush:migrate status': 21 return dt('List all content sets with current status'); 22 } 23 } 24 25 /** 26 * Implementation of hook_drush_command(). 27 */ 28 function migrate_drush_command() { 29 $migration_options = array( 30 '--itemlimit' => 'The maximum number of items to migrate. If unspecified, all are migrated', 31 '--feedback' => 'Frequency of progress messages, in seconds or items processed', 32 '--idlist' => 'A comma delimited list of ids to import or clear. If unspecified, migrate imports all pending items or clears all items for the content set.', 33 ); 34 $items['migrate status'] = array( 35 'callback' => 'drush_migrate_status', 36 'description' => 'List all content sets with current status.', 37 ); 38 $items['migrate all'] = array( 39 'callback' => 'drush_migrate_all', 40 'description' => 'Run the full migration process.', 41 'options' => $migration_options, 42 'examples' => array( 43 'migrate all' => 'Process all selected content sets completely', 44 'migrate all --itemlimit=50' => 'Process a maximum of 50 items from each selected content set', 45 'migrate all --feedback="60 seconds"' => 'Display a progress message every 60 seconds or less', 46 'migrate all --feedback="1000 items"' => 'Display a progress message every 1000 processed items or less', 47 ), 48 ); 49 $items['migrate clear'] = array( 50 'callback' => 'drush_migrate_clear', 51 'description' => 'Clear migrated data for the specified content set', 52 'options' => $migration_options, 53 'arguments' => array( 54 'content_set' => 'Name or mcsid of content set to clear', 55 ), 56 'examples' => array( 57 'migrate clear 4' => 'Clear the content set with mcsid 4', 58 'migrate clear 4 --idlist=4,9' => 'Clear two items in mcsid 4. The ids refer to the value of the primary key in base table', 59 'migrate clear Articles --itemlimit=50' => 60 'Clear up to 50 items from the content set named Articles', 61 'migrate clear Users --feedback="60 seconds"' => 'Display a progress message every 60 seconds or less', 62 'migrate clear 2 --feedback="1000 items"' => 'Display a progress message every 1000 processed items or less', 63 ), 64 ); 65 $items['migrate import'] = array( 66 'callback' => 'drush_migrate_import', 67 'description' => 'Import a given migration content set', 68 'options' => $migration_options, 69 'arguments' => array( 70 'content_set' => 'Name or mcsid of content set to import', 71 ), 72 'examples' => array( 73 'migrate import 4' => 'Import the content set with mcsid 4', 74 'migrate import 4 --idlist=4,9' => 'Import two items in mcsid 4. The ids refer to the value of the primary key in base table', 75 'migrate import Articles --itemlimit=50' => 76 'Import up to 50 items from the content set named Articles', 77 'migrate import Users --feedback="60 seconds"' => 'Display a progress message every 60 seconds or less', 78 'migrate import 2 --feedback="1000 items"' => 'Display a progress message every 1000 processed items or less', 79 ), 80 ); 81 return $items; 82 } 83 84 /** 85 * A simplified version of the Process (dashboard) page 86 * 87 */ 88 function drush_migrate_status() { 89 $table = array(); 90 $table[] = array(dt('Status'), dt('Name'), dt('Total'), dt('Imported'), dt('Unimported')); 91 $sql = "SELECT * 92 FROM {migrate_content_sets} 93 ORDER BY weight, contenttype, view_name"; 94 $result = db_query($sql); 95 while ($row = db_fetch_object($result)) { 96 if ($row->clearing) { 97 $status = dt('Clearing'); 98 } 99 elseif ($row->importing) { 100 $status = dt('Importing'); 101 } 102 elseif ($row->scanning) { 103 $status = dt('Scanning'); 104 } 105 else { 106 $status = dt(''); 107 } 108 $view = views_get_view($row->view_name); 109 if (!$view) { 110 drush_set_error(NULL, dt('View !view does not exist - either (re)create this view, or 111 remove the content set using it.', array('!view' => $row->view_name))); 112 continue; 113 } 114 $maptable = migrate_map_table_name($row->mcsid); 115 $imported = db_result(db_query('SELECT COUNT(*) FROM {' . $maptable . '}')); 116 // If not caching counts, override the saved count with a fresh count 117 if (!variable_get('migrate_cache_counts', 0)) { 118 $total = _migrate_get_view_count($view); 119 } 120 else { 121 $total = $row->rowcount; 122 } 123 124 $table[] = array($status, $row->description, $total, $imported, $total-$imported); 125 } 126 drush_print_table($table, TRUE); 127 } 128 129 /** 130 * Process all enabled operations 131 * 132 */ 133 function drush_migrate_all() { 134 drush_migrate_set_verbose(); 135 $messages = array(); 136 $options = array(); 137 $itemlimit = drush_get_option('itemlimit'); 138 if ($itemlimit) { 139 $options['itemlimit'] = $itemlimit; 140 } 141 $options['feedback'] = array( 142 'function' => 'drush_log', 143 ); 144 $feedback = drush_get_option('feedback'); 145 if ($feedback) { 146 $parts = explode(' ', $feedback); 147 $options['feedback']['frequency'] = $parts[0]; 148 $options['feedback']['frequency_unit'] = drupal_strtolower($parts[1]); 149 if ($options['feedback']['frequency_unit'] != 'seconds' && 150 $options['feedback']['frequency_unit'] != 'items') { 151 drush_set_error(NULL, dt("Invalid feedback frequency unit '!unit'", 152 array('!unit' => $options['feedback']['frequency_unit']))); 153 return; 154 } 155 } 156 migrate_content_process_all($messages, $options); 157 foreach ($messages as $message) { 158 drush_log($message); 159 } 160 } 161 162 /** 163 * Clear one specified content set 164 * 165 * @param $content_set 166 * The mcsid or the name of the content set 167 */ 168 function drush_migrate_clear($content_set) { 169 drush_migrate_set_verbose(); 170 if (is_numeric($content_set)) { 171 $mcsid = db_result(db_query("SELECT mcsid FROM {migrate_content_sets} 172 WHERE mcsid=%d", $content_set)); 173 } 174 else { 175 $mcsid = db_result(db_query("SELECT mcsid FROM {migrate_content_sets} 176 WHERE LOWER('%s') = LOWER(description)", $content_set)); 177 } 178 $messages = array(); 179 $options = array(); 180 if ($idlist = drush_get_option('idlist', FALSE)) { 181 $options['idlist'] = $idlist; 182 } 183 if ($itemlimit = drush_get_option('itemlimit', FALSE)) { 184 $options['itemlimit'] = $itemlimit; 185 } 186 $options['feedback'] = array( 187 'function' => 'drush_log', 188 ); 189 $feedback = drush_get_option('feedback'); 190 if ($feedback) { 191 $parts = explode(' ', $feedback); 192 $options['feedback']['frequency'] = $parts[0]; 193 $options['feedback']['frequency_unit'] = $parts[1]; 194 if ($options['feedback']['frequency_unit'] != 'seconds' && 195 $options['feedback']['frequency_unit'] != 'items') { 196 drush_set_error(NULL, dt("Invalid feedback frequency unit '!unit'", 197 array('!unit' => $options['feedback']['frequency_unit']))); 198 return; 199 } 200 } 201 migrate_content_process_clear($mcsid, $messages, $options); 202 foreach ($messages as $message) { 203 drush_log($message); 204 } 205 } 206 207 /** 208 * Import one specified content set 209 * 210 * @param $content_set 211 * The mcsid or the name of the content set 212 */ 213 function drush_migrate_import($content_set) { 214 drush_migrate_set_verbose(); 215 if (is_numeric($content_set)) { 216 $mcsid = db_result(db_query("SELECT mcsid FROM {migrate_content_sets} 217 WHERE mcsid=%d", $content_set)); 218 } 219 else { 220 $mcsid = db_result(db_query("SELECT mcsid FROM {migrate_content_sets} 221 WHERE LOWER('%s') = LOWER(description)", $content_set)); 222 } 223 $messages = array(); 224 $options = array(); 225 if ($idlist = drush_get_option('idlist', FALSE)) { 226 $options['idlist'] = $idlist; 227 } 228 if ($itemlimit = drush_get_option('itemlimit', FALSE)) { 229 $options['itemlimit'] = $itemlimit; 230 } 231 $options['feedback'] = array( 232 'function' => 'drush_log', 233 ); 234 $feedback = drush_get_option('feedback'); 235 if ($feedback) { 236 $parts = explode(' ', $feedback); 237 $options['feedback']['frequency'] = $parts[0]; 238 $options['feedback']['frequency_unit'] = $parts[1]; 239 if ($options['feedback']['frequency_unit'] != 'seconds' && 240 $options['feedback']['frequency_unit'] != 'items') { 241 drush_set_error(NULL, dt("Invalid feedback frequency unit '!unit'", 242 array('!unit' => $options['feedback']['frequency_unit']))); 243 return; 244 } 245 } 246 migrate_content_process_import($mcsid, $messages, $options); 247 foreach ($messages as $message) { 248 drush_log($message); 249 } 250 } 251 252 // Set the verbose context if 'feedback' is requested. 253 function drush_migrate_set_verbose() { 254 if (drush_get_option('feedback')) { 255 drush_set_context('DRUSH_VERBOSE', TRUE); 256 } 257 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |