metatag_importer.drush.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * Drush integration for the Metatag Importer module.
  5. */
  6. /**
  7. * Implements hook_drush_command().
  8. */
  9. function metatag_importer_drush_command() {
  10. // This needs to be fixed.
  11. // $items['metatag-convert-nodewords'] = array(
  12. // 'description' => dt('Convert data from Nodewords into Metatag.'),
  13. // 'drupal dependencies' => array('metatag'),
  14. // );
  15. $items['metatag-convert-page-title'] = array(
  16. 'description' => dt('Convert data from Page Title into Metatag.'),
  17. 'drupal dependencies' => array('metatag'),
  18. );
  19. return $items;
  20. }
  21. /**
  22. * Callback to convert all Nodewords data.
  23. */
  24. function drush_metatag_importer_metatag_convert_nodewords() {
  25. if (!drush_confirm(dt('Ready to convert all data from Nodewords?'))) {
  26. return;
  27. }
  28. // Need to make sure the Nodewords table actually exists.
  29. if (!db_table_exists('nodewords')) {
  30. drush_set_error('metatag_importer', dt('Could not find the nodewords table.'));
  31. return;
  32. }
  33. // Offload all of the logic to the code contained in the admin file.
  34. include('metatag_importer.nodewords.inc');
  35. // Start the import.
  36. // @todo This isn't working.
  37. _metatag_importer_import();
  38. drush_print(dt('Data converesion finished.'));
  39. }
  40. /**
  41. * Callback to convert Page Title data.
  42. */
  43. function drush_metatag_importer_metatag_convert_page_title() {
  44. if (!db_table_exists('page_title')) {
  45. drush_set_error('metatag_importer', dt('Could not find the page_title table!'));
  46. return;
  47. }
  48. $records = db_query("SELECT COUNT(id) FROM {page_title} WHERE type IN ('node', 'taxonomy_term', 'user')")->fetchField();
  49. if (empty($records)) {
  50. return dt('There are no page_title records to convert!');
  51. }
  52. if (!drush_confirm(dt('Ready to convert !count record(s) from Page Title?', array('!count' => $records)))) {
  53. return;
  54. }
  55. include('metatag_importer.page_title.inc');
  56. // Start the importer.
  57. $count = metatag_importer_for_page_title();
  58. drush_print(dt('Converted !count record(s) from the Page Title module.', array('!count' => $count)));
  59. }