-
Notifications
You must be signed in to change notification settings - Fork 8
/
feedapi2feeds.drush.inc
84 lines (79 loc) · 2.67 KB
/
feedapi2feeds.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
// $Id$
/**
* @file
* Drush commands for FeedAPI2Feeds migration.
*/
/**
* Implementation of hook_drush_help().
*/
function feedapi2feeds_drush_help($section) {
switch ($section) {
case 'drush:feedapi2feeds migrateAll':
return dt('Migrates all the FeedAPI content-types on the site to Feeds importer configurations');
case 'drush:feedapi2feeds migrate':
return dt('Migrates the given FeedAPI content-types on the site to Feeds importer configurations');
}
}
/**
* Implementation of hook_drush_command().
*/
function feedapi2feeds_drush_command() {
$items['feedapi2feeds migrateAll'] = array(
'callback' => 'feedapi2feeds_drush_migrate_all',
'description' => dt('Migrates all the FeedAPI content-types on the site to Feeds importer configurations')
);
$items['feedapi2feeds migrate'] = array(
'callback' => 'feedapi2feeds_drush_migrate',
'description' => dt('Migrates the given FeedAPI content-type to Feeds importer configurations'),
'arguments' => array(
'type' => 'Machine name of a FeedAPI content-type',
),
);
return $items;
}
/**
* Loops through all the content-types and migrate to Feeds importer configuration.
*/
function feedapi2feeds_drush_migrate_all() {
module_load_include('php', 'feedapi2feeds', 'feedapi2feeds');
$migration = new FeedAPI2Feeds();
$to_migrate = $migration->getTypesToMigrate();
if (empty($to_migrate)) {
return drush_set_error('DRUSH_FEEDAPI2FEEDS', dt('There is no FeedAPI-enabled content-type on the site.'));
}
try {
$migration->migrateAll();
} catch (Exception $e) {
drush_print("The migration process has been completed with the following errors:\n". $e->getMessage());
}
$msgs = $migration->getMessages();
foreach ($msgs as $msg) {
drush_print($msg);
}
drush_print(dt("The migration has been completed."));
}
/**
* Migrate one content-type to Feeds importer configuration.
*/
function feedapi2feeds_drush_migrate($type) {
module_load_include('php', 'feedapi2feeds', 'feedapi2feeds');
$migration = new FeedAPI2Feeds();
$to_migrate = $migration->getTypesToMigrate();
if (empty($to_migrate)) {
return drush_set_error('DRUSH_FEEDAPI2FEEDS', dt('There is no FeedAPI-enabled content-type on the site.'));
}
if (!in_array($type, $to_migrate)) {
return drush_set_error('DRUSH_FEEDAPI2FEEDS', dt('This is not a FeedAPI-enabled content-type, cannot migrate.'));
}
try {
$migration->migrateType($type);
} catch (Exception $e) {
drush_print("The migration was not successful:\n". $e->getMessage());
}
$msgs = $migration->getMessages();
foreach ($msgs as $msg) {
drush_print($msg);
}
drush_print(dt("The migration has been completed."));
}