metatag_importer.drush.inc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. $items['metatag-convert-metatags-quick'] = array(
  11. 'description' => dt('Convert data from Metatags Quick into Metatag'),
  12. 'drupal dependencies' => array('metatag', 'metatag_importer'),
  13. 'aliases' => array('mtcmq'),
  14. );
  15. $items['metatag-convert-nodewords'] = array(
  16. 'description' => dt('Convert data from Nodewords into Metatag.'),
  17. 'drupal dependencies' => array('metatag', 'metatag_importer'),
  18. 'aliases' => array('mtcnw'),
  19. );
  20. $items['metatag-convert-page-title'] = array(
  21. 'description' => dt('Convert data from Page Title into Metatag.'),
  22. 'drupal dependencies' => array('metatag', 'metatag_importer'),
  23. 'aliases' => array('mtcpt'),
  24. );
  25. return $items;
  26. }
  27. /**
  28. * Callback to convert all Metatags Quick data.
  29. */
  30. function drush_metatag_importer_metatag_convert_metatags_quick() {
  31. if (!drush_confirm(dt('Ready to convert all data from Metatags Quick?'))) {
  32. return;
  33. }
  34. include 'metatag_importer.metatags_quick.inc';
  35. metatag_importer_metatags_quick_import();
  36. }
  37. /**
  38. * Callback to convert all Nodewords data.
  39. */
  40. function drush_metatag_importer_metatag_convert_nodewords() {
  41. if (!drush_confirm(dt('Ready to convert all data from Nodewords?'))) {
  42. return;
  43. }
  44. // Need to make sure the Nodewords table actually exists.
  45. if (!db_table_exists('nodewords')) {
  46. drush_set_error('metatag_importer', dt('Could not find the nodewords table!'));
  47. return;
  48. }
  49. // Offload all of the logic to the code contained in the admin file.
  50. include 'metatag_importer.nodewords.inc';
  51. // Start the import.
  52. $types = array_keys(_metatag_importer_list_nodewords());
  53. _metatag_importer_import($types);
  54. drush_print(dt('Data converesion finished.'));
  55. }
  56. /**
  57. * Callback to convert Page Title data.
  58. */
  59. function drush_metatag_importer_metatag_convert_page_title() {
  60. if (!db_table_exists('page_title')) {
  61. drush_set_error('metatag_importer', dt('Could not find the page_title table!'));
  62. return;
  63. }
  64. $records = db_query("SELECT COUNT(id) FROM {page_title} WHERE type IN ('node', 'taxonomy_term', 'user')")->fetchField();
  65. if (empty($records)) {
  66. return dt('There are no page_title records to convert!');
  67. }
  68. if (!drush_confirm(dt('Ready to convert !count record(s) from Page Title?', array('!count' => $records)))) {
  69. return;
  70. }
  71. include 'metatag_importer.page_title.inc';
  72. // Start the importer.
  73. $count = metatag_importer_for_page_title();
  74. drush_print(dt('Converted !count record(s) from the Page Title module.', array('!count' => $count)));
  75. }