/[drupal]/contributions/modules/apachesolr/apachesolr.drush.inc
ViewVC logotype

Diff of /contributions/modules/apachesolr/apachesolr.drush.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Fri Nov 6 09:39:34 2009 UTC revision 1.1.2.1, Fri Nov 6 09:39:34 2009 UTC
# Line 0  Line 1 
1    <?php
2    // $Id: apachesolr.drush.inc,v 1.1.2.4 2009/09/15 13:33:04 robertDouglass Exp $
3    
4    /**
5     * @file
6     *   drush integration for apachesolr.
7     */
8    
9    /**
10     * Implementation of hook_drush_command().
11     *
12     * In this hook, you specify which commands your
13     * drush module makes available, what it does and
14     * description.
15     *
16     * Notice how this structure closely resembles how
17     * you define menu hooks.
18     *
19     * @See drush_parse_command() for a list of recognized keys.
20     *
21     * @return
22     *   An associative array describing your command(s).
23     */
24    function apachesolr_drush_command() {
25      $items = array();
26    
27      // the key in the $items array is the name of the command.
28      $items['solr delete index'] = array(
29        // the name of the function implementing your command.
30        'callback' => 'apachesolr_drush_solr_delete_index',
31        // a short description of your command
32        'description' => dt('Deletes the content from the index. Can take content types as parameters.'),
33        'arguments' => array(
34          'types' => dt('Optional. A space delimited list of content types to be deleted from the index.'),
35        ),
36      );
37      $items['solr reindex'] = array(
38        // the name of the function implementing your command.
39        'callback' => 'apachesolr_drush_solr_reindex',
40        // a short description of your command
41        'description' => dt('Marks content for reindexing. Can take content types as parameters.'),
42        'arguments' => array(
43          'types' => dt('Optional. A space delimited list of content types to be marked for reindexing.'),
44        ),
45      );
46      $items['solr phpclient'] = array(
47        'callback' => 'apachesolr_drush_solr_phpclient',
48        'description' => dt('Downloads the required SolrPhpClient from googlecode.com.'),
49        'arguments' => array(
50          'path' => dt('Optional. A path to the apachesolr module. If omitted Drush will use the default location.'),
51        ),
52      );
53      $items['solr search'] = array(
54        'callback' => 'apachesolr_drush_solr_search',
55        'description' => dt('Search the site for keywords using Apache Solr'),
56        'arguments' => array(
57          'keywords' => dt('One or more keywords, separated by spaces.'),
58        ),
59      );
60      return $items;
61    }
62    
63    /**
64     * Implementation of hook_drush_help().
65     *
66     * This function is called whenever a drush user calls
67     * 'drush help <name-of-your-command>'
68     *
69     * @param
70     *   A string with the help section (prepend with 'drush:')
71     *
72     * @return
73     *   A string with the help text for your command.
74     */
75    function apachesolr_drush_help($section) {
76      switch ($section) {
77        case 'drush:solr delete index':
78          return dt("Used without parameters, this command deletes the entire Solr index. Used with parameters for content type, it deletes just the content types that are specified. After the index has been deleted, all content will be indexed again on future cron runs.");
79        case 'drush:solr reindex':
80          return dt("Used without parameters, this command marks all of the content in the Solr index for reindexing. Used with paramters for content type, it marks just the content types that are specified. Reindexing is different than deleting as the content is still searchable while it is in queue to be reindexed. Reindexing is done on future cron runs.");
81        case 'drush:solr phpclient':
82          return dt("Downloads the SolrPhpClient libraray from googlecode.com. Include the optional path to an apachesolr module installation if you have more than one, or if the module is not yet enabled.");
83        case 'drush:solr search':
84          return dt('Executes a search against the site\'s Apache Solr search index and returns the restults.');
85      }
86    }
87    
88    /**
89     * Example drush command callback.
90     *
91     * This is where the action takes place.
92     *
93     * In this function, all of Drupals API is (usually) available, including
94     * any functions you have added in your own modules/themes.
95     *
96     * To print something to the terminal window, use drush_print().
97     *
98     */
99    function apachesolr_drush_solr_delete_index() {
100      $args = func_get_args();
101      $path = drupal_get_path('module', 'apachesolr');
102      include_once($path . "/apachesolr.admin.inc");
103      if (count($args) > 0) {
104        foreach ($args as $type) {
105          apachesolr_delete_index($type);
106        }
107      }
108      else {
109        apachesolr_delete_index();
110      }
111    }
112    
113    function apachesolr_drush_solr_reindex() {
114      $args = func_get_args();
115      if (count($args) > 0) {
116        foreach ($args as $type) {
117          apachesolr_rebuild_index_table($type);
118        }
119      }
120      else {
121        apachesolr_rebuild_index_table();
122      }
123    }
124    
125    function apachesolr_drush_solr_phpclient() {
126      $args = func_get_args();
127      if ($args[0]) {
128        $path = $args[0];
129      }
130      else {
131        $path = drupal_get_path('module', 'apachesolr');
132      }
133      drush_op('chdir', $path);
134      if (drush_shell_exec('svn export -r6 http://solr-php-client.googlecode.com/svn/trunk/ SolrPhpClient')) {
135        drush_log(dt('SolrPhpClient has been downloaded to @path', array('@path' => $path)), 'success');
136      }
137      else {
138        drush_log(dt('Drush was unable to download the SolrPhpClient to @path', array('@path' => $path)), 'error');
139      }
140    }
141    
142    function apachesolr_drush_solr_search() {
143      $args = func_get_args();
144      $keys = implode(' ', $args);
145      foreach(apachesolr_search_execute($keys) as $result) {
146        $output = 'node/' . $result['node']->nid . ' ' . dt('by @name (user/@uid)', array('@name' => strip_tags($result['user']), '@uid' => $result['node']->uid)) . "\n";
147        $output .= dt('title: ') .  $result['title'] . "\n";
148        $output .= preg_replace('/[\s]+/', ' ', strip_tags($result['snippet'])) . "\n\n";
149        drush_print($output);
150      }
151    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2