'drush_sm_list', 'description' => t('List the available system items from : @l', array( '@l' => _drush_sm_service_strings())), ); $items['sm export'] = array( 'callback' => 'drush_sm_export', 'description' => t('Export a system aspect like : @l', array( '@l' => _drush_sm_service_strings())), ); $items['sm report'] = array( 'callback' => 'drush_sm_report', 'description' => t('Report a system aspect like : @l', array( '@l' => _drush_sm_service_strings())), ); /* $items['sm create db'] = array( 'callback' => 'drush_sm_create_db', 'description' => t('Create a new database.'), ); */ return $items; } function _drush_sm_services() { return array('cck','views', 'variables'); } function _drush_sm_service_strings() { return '[' . implode( "|" , _drush_sm_services()) . ']'; } function _drush_sm_command() { return array( 'list', 'export', 'report'); } function _drush_sm_command_strings() { return '[' . implode( "|" , _drush_sm_command()) . ']'; } function _drush_sm_usage() { return '[' . _drush_sm_command() . "] [" . _drush_sm_services() . ']'; } function drush_sm_list() { $args = func_get_args(); if ($args) { $command=array_shift($args); if (!in_array($command, _drush_sm_services())) { drush_die('Unknown list argument ' . $command); } else { array_unshift($args, 'list'); call_user_func_array('_drush_sm_' . $command, $args); } } else { drush_die('No args given. Try : ' . _drush_sm_service_strings()); } } function drush_sm_export() { $args = func_get_args(); if ($args) { $command=array_shift($args); array_unshift($args, 'export'); if (!in_array($command, _drush_sm_services())) { drush_die('Unknown list argument ' . $command); } else { call_user_func_array('_drush_sm_' . $command, $args); } } else { drush_die('No args given. Try : ' . implode(', ', _drush_sm_services())); } } function drush_sm_report() { $args = func_get_args(); if ($args) { $command=array_shift($args); if (!in_array($command, _drush_sm_services())) { drush_die('Unknown list argument ' . $command); } else { array_unshift($args, 'report'); call_user_func_array('_drush_sm_' . $command, $args); } } else { drush_die('No args given. Try : ' . _drush_sm_service_strings()); } } function _drush_sm_variables() { $args = func_get_args(); $command=array_shift($args); if ($command=='list') { echo "// listing ... \n"; $args = func_get_args(); $command=array_shift($args); $report=_drush_sm_variables_sql(); foreach ($report as $name => $value) { echo "\n" . $name; } } else if ($command=='export') { $args = func_get_args(); $command=array_shift($args); $report=_drush_sm_variables_sql(); echo '$drush_sm_var_import=' . var_export($report, TRUE); } else if ($command=='report') { echo "// Reporting ... \n"; $report=_drush_sm_variables_sql(); foreach ($report as $name => $value) { $var_get=variable_get($name); if (!isset($var_get) || $var_get !== $value) { echo $name . " overridden by " . var_export($var_get, TRUE) ."\n"; } } } else { drush_die('Unknown variables command ' . $command); } } function _drush_sm_variables_sql() { $sql= "select * from {variable} order by name"; $result=db_query($sql); $return=array(); while ($record = db_fetch_array($result)) { $name = $record['name']; $value=unserialize($record['value']); $return[$name]=$value; } return $return; } function _drush_sm_views() { if (function_exists('views_get_all_views')) { $args = func_get_args(); $command=array_shift($args); if ($command=='list') { _drush_sm_views_list(); } else if ($command=='export') { $result=call_user_func_array('_drush_sm_views_export', $args); } else { drush_die('Unknown views command ' . $command); } } else { drush_die('views not installed'); } } function _drush_sm_views_list() { $views=views_get_all_views(); foreach ($views as $name => $view) { echo "$name\n"; } } function _drush_sm_views_export() { $args=func_get_args(); $dir=array_shift($args); $views=views_get_all_views(); foreach ($views as $name => $view) { $code = views_views_exportables('export', array($name => TRUE), $name); if ($dir) { $file=$dir . 'views_' . $name . '.txt'; if (DRUSH_SIMULATE) { drush_verbose( "Should write to file $file"); } else { drush_verbose( "Writing file $file"); file_put_contents( $file, $code); } } else { echo "$name\n"; if (!DRUSH_SIMULATE) { echo $code; } } } } function _drush_sm_views_report() { echo "Not yet implemented"; } function _drush_sm_cck() { $args = func_get_args(); if (function_exists('content_copy_types')) { $command=array_shift($args); if ($command=='list') { $content_types=content_copy_types(); foreach ($content_types as $content_type => $item) { echo "$content_type\n"; $fields = content_copy_fields($content_type); foreach ($fields as $field) { echo " $field\n"; } } } else if ($command=='export') { require_once './includes/common.inc'; //module_load_inc('inc', 'node', 'content_types'); module_load_include('inc', 'content', 'includes/content.admin'); module_load_include('inc', 'content', 'includes/content.crud'); $content_defs=content_field_instance_read(); $dir=array_shift($args); foreach ($content_defs as $def) { $field_name= 'cck_' . $def['type_name'] . '_' . $def['field_name']; $code=var_export( $def, TRUE); if ($dir) { $file=$dir . $field_name . '.txt'; if (DRUSH_SIMULATE) { drush_verbose( "Should write to file $file"); } else { drush_verbose( "Writing file $file"); $result=file_put_contents( $file, $code . "\n"); if ($result===FALSE) { drush_die('nop'); } } } else { echo "\n// " . $field_name . "\n"; echo $code; echo "\n"; } } } else { drush_die('Unknown cck command ' . $command); } } else { drush_die('cck not installed'); } } /** * // http://usr:pwd@www.test.com:81/dir/dir.2/index.htm?q1=value&q2=test#top // @see http://stevenlevithan.com/demo/parseuri/cf/ * @param uri */ function drush_sm_create_db() { $args = func_get_args(); $uri = $args[0]; // parse_url() # $url = 'mysql://drush_mm:drush_mm@localhost/drush_mm'; $HOSTNAME = 'test'; $protocol = 'mysql'; $user = $HOSTNAME; $password = $HOSTNAME; $host = 'localhost'; $resource = $HOSTNAME; $template = "create database $resource; \n"; $template.= "grant all on $resource.* to '$user'@'$host' identified by '$password'; \n"; db_query( $template); }