search_api.drush.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <?php
  2. /**
  3. * @file
  4. * Drush commands for SearchAPI.
  5. *
  6. * Original file by agentrickard for Palantir.net
  7. */
  8. /**
  9. * Implements hook_drush_command().
  10. */
  11. function search_api_drush_command() {
  12. $items = array();
  13. $items['search-api-list'] = array(
  14. 'description' => 'List all search indexes.',
  15. 'examples' => array(
  16. 'drush searchapi-list' => dt('List all search indexes.'),
  17. 'drush sapi-l' => dt('Alias to list all search indexes.'),
  18. ),
  19. 'aliases' => array('sapi-l'),
  20. );
  21. $items['search-api-enable'] = array(
  22. 'description' => 'Enable one or all disabled search_api indexes.',
  23. 'examples' => array(
  24. 'drush searchapi-enable' => dt('Enable all disabled indexes.'),
  25. 'drush sapi-en' => dt('Alias to enable all disabled indexes.'),
  26. 'drush sapi-en 1' => dt('Enable index with the ID !id.', array('!id' => 1)),
  27. ),
  28. 'arguments' => array(
  29. 'index_id' => dt('The numeric ID or machine name of an index to enable.'),
  30. ),
  31. 'aliases' => array('sapi-en'),
  32. );
  33. $items['search-api-disable'] = array(
  34. 'description' => 'Disable one or all enabled search_api indexes.',
  35. 'examples' => array(
  36. 'drush searchapi-disable' => dt('Disable all enabled indexes.'),
  37. 'drush sapi-dis' => dt('Alias to disable all enabled indexes.'),
  38. 'drush sapi-dis 1' => dt('Disable index with the ID !id.', array('!id' => 1)),
  39. ),
  40. 'arguments' => array(
  41. 'index_id' => dt('The numeric ID or machine name of an index to disable.'),
  42. ),
  43. 'aliases' => array('sapi-dis'),
  44. );
  45. $items['search-api-status'] = array(
  46. 'description' => 'Show the status of one or all search indexes.',
  47. 'examples' => array(
  48. 'drush searchapi-status' => dt('Show the status of all search indexes.'),
  49. 'drush sapi-s' => dt('Alias to show the status of all search indexes.'),
  50. 'drush sapi-s 1' => dt('Show the status of the search index with the ID !id.', array('!id' => 1)),
  51. 'drush sapi-s default_node_index' => dt('Show the status of the search index with the machine name !name.', array('!name' => 'default_node_index')),
  52. ),
  53. 'arguments' => array(
  54. 'index_id' => dt('The numeric ID or machine name of an index.'),
  55. ),
  56. 'aliases' => array('sapi-s'),
  57. );
  58. $items['search-api-index'] = array(
  59. 'description' => 'Index items for one or all enabled search_api indexes.',
  60. 'examples' => array(
  61. 'drush searchapi-index' => dt('Index items for all enabled indexes.'),
  62. 'drush sapi-i' => dt('Alias to index items for all enabled indexes.'),
  63. 'drush sapi-i 1' => dt('Index items for the index with the ID !id.', array('!id' => 1)),
  64. 'drush sapi-i default_node_index' => dt('Index items for the index with the machine name !name.', array('!name' => 'default_node_index')),
  65. 'drush sapi-i 1 100' => dt("Index a maximum number of !limit items (index's cron batch size items per batch run) for the index with the ID !id.", array('!limit' => 100, '!id' => 1)),
  66. 'drush sapi-i 1 100 10' => dt("Index a maximum number of !limit items (!batch_size items per batch run) for the index with the ID !id.", array('!limit' => 100, '!batch_size' => 10, '!id' => 1)),
  67. 'drush sapi-i 0 0 100' => dt("Index all items of all indexes with !batch_size items per batch run.", array('!batch_size' => 100)),
  68. ),
  69. 'arguments' => array(
  70. 'index_id' => dt('The numeric ID or machine name of an index. Set to 0 to index all indexes. Defaults to 0 (index all).'),
  71. 'limit' => dt("The number of items to index (index's cron batch size items per run). Set to 0 to index all items. Defaults to 0 (index all)."),
  72. 'batch_size' => dt("The number of items to index per batch run. Set to 0 to index all items at once. Defaults to the index's cron batch size."),
  73. ),
  74. 'aliases' => array('sapi-i'),
  75. );
  76. $items['search-api-reindex'] = array(
  77. 'description' => 'Force reindexing of one or all search indexes, without clearing existing index data.',
  78. 'examples' => array(
  79. 'drush searchapi-reindex' => dt('Schedule all search indexes for reindexing.'),
  80. 'drush sapi-r' => dt('Alias to schedule all search indexes for reindexing .'),
  81. 'drush sapi-r 1' => dt('Schedule the search index with the ID !id for re-indexing.', array('!id' => 1)),
  82. 'drush sapi-r default_node_index' => dt('Schedule the search index with the machine name !name for re-indexing.', array('!name' => 'default_node_index')),
  83. ),
  84. 'arguments' => array(
  85. 'index_id' => dt('The numeric ID or machine name of an index.'),
  86. ),
  87. 'aliases' => array('sapi-r'),
  88. );
  89. $items['search-api-clear'] = array(
  90. 'description' => 'Clear one or all search indexes and mark them for re-indexing.',
  91. 'examples' => array(
  92. 'drush searchapi-clear' => dt('Clear all search indexes.'),
  93. 'drush sapi-c' => dt('Alias to clear all search indexes.'),
  94. 'drush sapi-c 1' => dt('Clear the search index with the ID !id.', array('!id' => 1)),
  95. 'drush sapi-c default_node_index' => dt('Clear the search index with the machine name !name.', array('!name' => 'default_node_index')),
  96. ),
  97. 'arguments' => array(
  98. 'index_id' => dt('The numeric ID or machine name of an index.'),
  99. ),
  100. 'aliases' => array('sapi-c'),
  101. );
  102. $items['search-api-set-index-server'] = array(
  103. 'description' => 'Set the search server used by a given index.',
  104. 'examples' => array(
  105. 'drush search-api-set-index-server default_node_index my_solr_server' => dt('Set the !index index to use the !server server.', array('!index' => 'default_node_index', '!server' => 'my_solr_server')),
  106. 'drush sapi-sis default_node_index my_solr_server' => dt('Alias to set the !index index to use the !server server.', array('!index' => 'default_node_index', '!server' => 'my_solr_server')),
  107. ),
  108. 'arguments' => array(
  109. 'index_id' => dt('The numeric ID or machine name of an index.'),
  110. 'server_id' => dt('The numeric ID or machine name of a server to set on the index.'),
  111. ),
  112. 'aliases' => array('sapi-sis'),
  113. );
  114. $items['search-api-server-list'] = array(
  115. 'description' => 'List all search servers.',
  116. 'examples' => array(
  117. 'drush search-api-server-list' => dt('List all search servers.'),
  118. 'drush sapi-sl' => dt('Alias to list all search servers.'),
  119. ),
  120. 'aliases' => array('sapi-sl'),
  121. );
  122. $items['search-api-server-enable'] = array(
  123. 'description' => 'Enable a search server.',
  124. 'examples' => array(
  125. 'drush search-api-server-e my_solr_server' => dt('Enable the !server search server.', array('!server' => 'my_solr_server')),
  126. 'drush sapi-se my_solr_server' => dt('Alias to enable the !server search server.', array('!server' => 'my_solr_server')),
  127. ),
  128. 'arguments' => array(
  129. 'server_id' => dt('The numeric ID or machine name of a search server to enable.'),
  130. ),
  131. 'aliases' => array('sapi-se'),
  132. );
  133. $items['search-api-server-disable'] = array(
  134. 'description' => 'Disable a search server.',
  135. 'examples' => array(
  136. 'drush search-api-server-disable' => dt('Disable the !server search server.', array('!server' => 'my_solr_server')),
  137. 'drush sapi-sd' => dt('Alias to disable the !server search server.', array('!server' => 'my_solr_server')),
  138. ),
  139. 'arguments' => array(
  140. 'server_id' => dt('The numeric ID or machine name of a search server to disable.'),
  141. ),
  142. 'aliases' => array('sapi-sd'),
  143. );
  144. return $items;
  145. }
  146. /**
  147. * List all search indexes.
  148. */
  149. function drush_search_api_list() {
  150. if (search_api_drush_static(__FUNCTION__)) {
  151. return;
  152. }
  153. // See search_api_list_indexes()
  154. $indexes = search_api_index_load_multiple(FALSE);
  155. if (empty($indexes)) {
  156. drush_print(dt('There are no indexes present.'));
  157. return;
  158. }
  159. $rows[] = array(
  160. dt('Id'),
  161. dt('Name'),
  162. dt('Index'),
  163. dt('Server'),
  164. dt('Type'),
  165. dt('Status'),
  166. dt('Limit'),
  167. );
  168. foreach ($indexes as $index) {
  169. $type = search_api_get_item_type_info($index->item_type);
  170. $type = isset($type['name']) ? $type['name'] : $index->item_type;
  171. try {
  172. $server = $index->server();
  173. $server = $server ? $server->name : '(' . dt('none') . ')';
  174. }
  175. catch (SearchApiException $e) {
  176. watchdog_exception('search_api', $e);
  177. $server = '(' . dt('unknown: !server', array('server' => $index->server)) . ')';
  178. }
  179. $row = array(
  180. $index->id,
  181. $index->name,
  182. $index->machine_name,
  183. $server,
  184. $type,
  185. $index->enabled ? dt('enabled') : dt('disabled'),
  186. $index->options['cron_limit'],
  187. );
  188. $rows[] = $row;
  189. }
  190. drush_print_table($rows);
  191. }
  192. /**
  193. * Enable index(es).
  194. *
  195. * @param string|integer $index_id
  196. * The index name or id which should be enabled.
  197. */
  198. function drush_search_api_enable($index_id = NULL) {
  199. if (search_api_drush_static(__FUNCTION__)) {
  200. return;
  201. }
  202. $indexes = search_api_drush_get_index($index_id);
  203. if (empty($indexes)) {
  204. return;
  205. }
  206. foreach ($indexes as $index) {
  207. $vars = array('!index' => $index->name);
  208. if (!$index->enabled) {
  209. drush_log(dt("Enabling index !index and queueing items for indexing.", $vars), 'notice');
  210. $success = FALSE;
  211. try {
  212. if ($success = search_api_index_enable($index->id)) {
  213. drush_log(dt("The index !index was successfully enabled.", $vars), 'ok');
  214. }
  215. }
  216. catch (SearchApiException $e) {
  217. drush_log($e->getMessage(), 'error');
  218. }
  219. if (!$success) {
  220. drush_log(dt("Error enabling index !index.", $vars), 'error');
  221. }
  222. }
  223. else {
  224. drush_log(dt("The index !index is already enabled.", $vars), 'error');
  225. }
  226. }
  227. }
  228. /**
  229. * Disable index(es).
  230. *
  231. * @param string|integer $index_id
  232. * The index name or id which should be disabled.
  233. */
  234. function drush_search_api_disable($index_id = NULL) {
  235. if (search_api_drush_static(__FUNCTION__)) {
  236. return;
  237. }
  238. $indexes = search_api_drush_get_index($index_id);
  239. if (empty($indexes)) {
  240. return;
  241. }
  242. foreach ($indexes as $index) {
  243. $vars = array('!index' => $index->name);
  244. if ($index->enabled) {
  245. $success = FALSE;
  246. try {
  247. if ($success = search_api_index_disable($index->id)) {
  248. drush_log(dt("The index !index was successfully disabled.", $vars), 'ok');
  249. }
  250. }
  251. catch (SearchApiException $e) {
  252. drush_log($e->getMessage(), 'error');
  253. }
  254. if (!$success) {
  255. drush_log(dt("Error disabling index !index.", $vars), 'error');
  256. }
  257. }
  258. else {
  259. drush_log(dt("The index !index is already disabled.", $vars), 'error');
  260. }
  261. }
  262. }
  263. /**
  264. * Display index status.
  265. */
  266. function drush_search_api_status($index_id = NULL) {
  267. if (search_api_drush_static(__FUNCTION__)) {
  268. return;
  269. }
  270. $indexes = search_api_drush_get_index($index_id);
  271. if (empty($indexes)) {
  272. return;
  273. }
  274. // See search_api_index_status()
  275. $rows = array(array(
  276. dt('Id'),
  277. dt('Index'),
  278. dt('% Complete'),
  279. dt('Indexed'),
  280. dt('Total'),
  281. ));
  282. foreach ($indexes as $index) {
  283. $status = search_api_index_status($index);
  284. $complete = ($status['total'] > 0) ? 100 * round($status['indexed'] / $status['total'], 3) . '%' : '-';
  285. $row = array(
  286. $index->id,
  287. $index->name,
  288. $complete,
  289. $status['indexed'],
  290. $status['total'],
  291. );
  292. $rows[] = $row;
  293. }
  294. drush_print_table($rows);
  295. }
  296. /**
  297. * Index items.
  298. *
  299. * @param string|integer $index_id
  300. * The index name or id for which items should be indexed.
  301. * @param integer $limit
  302. * Maximum number of items to index.
  303. * @param integer $batch_size
  304. * Number of items to index per batch.
  305. */
  306. function drush_search_api_index($index_id = NULL, $limit = NULL, $batch_size = NULL) {
  307. if (search_api_drush_static(__FUNCTION__)) {
  308. return;
  309. }
  310. $index_id = !empty($index_id) ? $index_id : NULL;
  311. $indexes = search_api_drush_get_index($index_id);
  312. if (empty($indexes)) {
  313. return;
  314. }
  315. $process_batch = FALSE;
  316. foreach ($indexes as $index) {
  317. if (_drush_search_api_batch_indexing_create($index, $limit, $batch_size)) {
  318. $process_batch = TRUE;
  319. }
  320. }
  321. if ($process_batch) {
  322. drush_backend_batch_process();
  323. }
  324. }
  325. /**
  326. * Creates and sets a batch for indexing items for a particular index.
  327. *
  328. * @param SearchApiIndex $index
  329. * The index for which items should be indexed.
  330. * @param int $limit
  331. * (optional) The maximum number of items to index, or NULL to index all
  332. * items.
  333. * @param int $batch_size
  334. * (optional) The number of items to index per batch, or NULL to index all
  335. * items at once.
  336. *
  337. * @return bool
  338. * TRUE if batch was created, FALSE otherwise.
  339. */
  340. function _drush_search_api_batch_indexing_create(SearchApiIndex $index, $limit = NULL, $batch_size = NULL) {
  341. // Get the number of remaining items to index.
  342. try {
  343. $datasource = $index->datasource();
  344. }
  345. catch (SearchApiException $e) {
  346. drush_log($e->getMessage(), 'error');
  347. return FALSE;
  348. }
  349. $index_status = $datasource->getIndexStatus($index);
  350. $remaining = $index_status['total'] - $index_status['indexed'];
  351. if ($remaining <= 0) {
  352. drush_log(dt("The index !index is up to date.", array('!index' => $index->name)), 'ok');
  353. return FALSE;
  354. }
  355. // Get the number of items to index per batch run.
  356. if (!isset($batch_size)) {
  357. $batch_size = empty($index->options['cron_limit']) ? SEARCH_API_DEFAULT_CRON_LIMIT : $index->options['cron_limit'];
  358. }
  359. elseif ($batch_size <= 0) {
  360. $batch_size = $remaining;
  361. }
  362. // Get the total number of items to index.
  363. if (!isset($limit) || !is_int($limit += 0) || $limit <= 0) {
  364. $limit = $remaining;
  365. }
  366. drush_log(dt("Indexing a maximum number of !limit items (!batch_size items per batch run) for the index !index.", array('!index' => $index->name, '!limit' => $limit, '!batch_size' => $batch_size)), 'ok');
  367. // Create the batch.
  368. if (!_search_api_batch_indexing_create($index, $batch_size, $limit, $remaining, TRUE)) {
  369. drush_log(dt("Couldn't create a batch, please check the batch size and limit parameters."), 'error');
  370. return FALSE;
  371. }
  372. return TRUE;
  373. }
  374. /**
  375. * Copy of formal_plural that works with drush as 't' may not be available.
  376. */
  377. function _search_api_drush_format_plural($count, $singular, $plural, array $args = array(), array $options = array()) {
  378. $args['@count'] = $count;
  379. if ($count == 1) {
  380. return dt($singular, $args, $options);
  381. }
  382. // Get the plural index through the gettext formula.
  383. $index = (function_exists('locale_get_plural')) ? locale_get_plural($count, isset($options['langcode']) ? $options['langcode'] : NULL) : -1;
  384. // If the index cannot be computed, use the plural as a fallback (which
  385. // allows for most flexiblity with the replaceable @count value).
  386. if ($index < 0) {
  387. return dt($plural, $args, $options);
  388. }
  389. else {
  390. switch ($index) {
  391. case "0":
  392. return dt($singular, $args, $options);
  393. case "1":
  394. return dt($plural, $args, $options);
  395. default:
  396. unset($args['@count']);
  397. $args['@count[' . $index . ']'] = $count;
  398. return dt(strtr($plural, array('@count' => '@count[' . $index . ']')), $args, $options);
  399. }
  400. }
  401. }
  402. /**
  403. * Mark for re-indexing.
  404. */
  405. function drush_search_api_reindex($index_id = NULL) {
  406. if (search_api_drush_static(__FUNCTION__)) {
  407. return;
  408. }
  409. $indexes = search_api_drush_get_index($index_id);
  410. if (empty($indexes)) {
  411. return;
  412. }
  413. // See search_api_index_reindex()
  414. foreach ($indexes as $index) {
  415. $index->reindex();
  416. drush_log(dt('!index was successfully marked for re-indexing.', array('!index' => $index->machine_name)), 'ok');
  417. }
  418. }
  419. /**
  420. * Clear an index.
  421. */
  422. function drush_search_api_clear($index_id = NULL) {
  423. if (search_api_drush_static(__FUNCTION__)) {
  424. return;
  425. }
  426. $indexes = search_api_drush_get_index($index_id);
  427. if (empty($indexes)) {
  428. return;
  429. }
  430. // See search_api_index_reindex()
  431. foreach ($indexes as $index) {
  432. $index->clear();
  433. drush_log(dt('!index was successfully cleared.', array('!index' => $index->machine_name)), 'ok');
  434. }
  435. }
  436. /**
  437. * Set the server for a given index.
  438. */
  439. function drush_search_api_set_index_server($index_id = NULL, $server_id = NULL) {
  440. if (search_api_drush_static(__FUNCTION__)) {
  441. return;
  442. }
  443. // Make sure we have parameters to work with.
  444. if (empty($index_id) || empty($server_id)) {
  445. drush_log(dt('You must specify both an index and server.'), 'error');
  446. return;
  447. }
  448. // Fetch current index and server data.
  449. $indexes = search_api_drush_get_index($index_id);
  450. $servers = search_api_drush_get_server($server_id);
  451. if (empty($indexes) || empty($servers)) {
  452. // If the specified index or server can't be found, just return. An
  453. // appropriate error message should have been printed already.
  454. return;
  455. }
  456. // Set the new server on the index.
  457. $success = FALSE;
  458. $index = reset($indexes);
  459. $server = reset($servers);
  460. try {
  461. $success = $index->update(array('server' => $server->machine_name));
  462. }
  463. catch (SearchApiException $e) {
  464. drush_log($e->getMessage(), 'error');
  465. }
  466. if ($success === FALSE) {
  467. drush_log(dt('There was an error setting index !index to use server !server.', array('!index' => $index->name, '!server' => $server->name)), 'error');
  468. }
  469. elseif (!$success) {
  470. drush_log(dt('Index !index was already using server !server.', array('!index' => $index->name, '!server' => $server->name)), 'ok');
  471. }
  472. else {
  473. drush_log(dt('Index !index has been set to use server !server and items have been queued for indexing.', array('!index' => $index->name, '!server' => $server->name)), 'ok');
  474. }
  475. }
  476. /**
  477. * Returns an index or all indexes as an array.
  478. *
  479. * @param string|int|null $index_id
  480. * (optional) The ID or machine name of the index to load. Defaults to
  481. * loading all available indexes.
  482. *
  483. * @return SearchApiIndex[]
  484. * An array of indexes.
  485. */
  486. function search_api_drush_get_index($index_id = NULL) {
  487. $ids = isset($index_id) ? array($index_id) : FALSE;
  488. $indexes = search_api_index_load_multiple($ids);
  489. if (empty($indexes)) {
  490. drush_set_error(dt('Invalid index_id or no indexes present. Listing all indexes:'));
  491. drush_print();
  492. drush_search_api_list();
  493. }
  494. return $indexes;
  495. }
  496. /**
  497. * Returns a server or all servers as an array.
  498. *
  499. * @param string|int|null $server_id
  500. * (optional) The ID or machine name of the server to load. Defaults to
  501. * loading all available servers.
  502. *
  503. * @return SearchApiServer[]
  504. * An array of servers.
  505. */
  506. function search_api_drush_get_server($server_id = NULL) {
  507. $ids = isset($server_id) ? array($server_id) : FALSE;
  508. $servers = search_api_server_load_multiple($ids);
  509. if (empty($servers)) {
  510. drush_set_error(dt('Invalid server_id or no servers present.'));
  511. drush_print();
  512. drush_search_api_server_list();
  513. }
  514. return $servers;
  515. }
  516. /**
  517. * Does a static lookup to prevent Drush 4 from running twice.
  518. *
  519. * @param string $function
  520. * The Drush function being called.
  521. *
  522. * @return bool
  523. * TRUE if the function was already called in this Drush execution, FALSE
  524. * otherwise.
  525. *
  526. * @see http://drupal.org/node/704848
  527. */
  528. function search_api_drush_static($function) {
  529. static $index = array();
  530. if (isset($index[$function])) {
  531. return TRUE;
  532. }
  533. $index[$function] = TRUE;
  534. return FALSE;
  535. }
  536. /**
  537. * Lists all search servers.
  538. */
  539. function drush_search_api_server_list() {
  540. if (search_api_drush_static(__FUNCTION__)) {
  541. return;
  542. }
  543. $servers = search_api_server_load_multiple(FALSE);
  544. if (empty($servers)) {
  545. drush_print(dt('There are no servers present.'));
  546. return;
  547. }
  548. $rows[] = array(
  549. dt('Machine name'),
  550. dt('Name'),
  551. dt('Status'),
  552. );
  553. foreach ($servers as $server) {
  554. $row = array(
  555. $server->machine_name,
  556. $server->name,
  557. $server->enabled ? dt('enabled') : dt('disabled'),
  558. );
  559. $rows[] = $row;
  560. }
  561. drush_print_table($rows);
  562. }
  563. /**
  564. * Enables a search server.
  565. *
  566. * @param int|string $server_id
  567. * The numeric ID or machine name of the server to enable.
  568. */
  569. function drush_search_api_server_enable($server_id = NULL) {
  570. if (!isset($server_id)) {
  571. drush_print(dt('Please provide a valid server id.'));
  572. return;
  573. }
  574. $server = search_api_server_load($server_id);
  575. if (empty($server)) {
  576. drush_print(dt('The server was not able to load.'));
  577. return;
  578. }
  579. else {
  580. $server->update(array('enabled' => 1));
  581. drush_print(dt('The server was enabled successfully.'));
  582. }
  583. }
  584. /**
  585. * Disables a search server.
  586. *
  587. * @param int|string $server_id
  588. * The numeric ID or machine name of the server to disable.
  589. */
  590. function drush_search_api_server_disable($server_id = NULL) {
  591. if (!isset($server_id)) {
  592. drush_print(dt('Please provide a valid server id.'));
  593. return;
  594. }
  595. $server = search_api_server_load($server_id);
  596. if (empty($server)) {
  597. drush_print(dt('The server was not able to load.'));
  598. return;
  599. }
  600. else {
  601. $server->update(array('enabled' => 0));
  602. drush_print(dt('The server was disabled successfully.'));
  603. }
  604. }