diff --exclude-from=/Users/jasonpkirst/.diffignore -N -urp ../dbscripts/dbscripts.drush.inc /Users/jasonpkirst/.drush/dbscripts/dbscripts.drush.inc --- ../dbscripts/dbscripts.drush.inc 1969-12-31 21:00:00.000000000 -0300 +++ /Users/jasonpkirst/.drush/dbscripts/dbscripts.drush.inc 2009-08-05 01:48:46.000000000 -0300 @@ -0,0 +1,141 @@ + 'dbscripts_dump_drush', + 'description' => "Dump the database from MySQL to a given branch of dump files.", + ); + + $items['dbscripts restore'] = array( + 'callback' => 'dbscripts_restore_drush', + 'description' => "Restores the database from a given branch.", + ); + + $items['dbscripts erase'] = array( + 'callback' => 'dbscripts_erase_drush', + 'description' => "Erases the database within the MySQL database.", + ); + + $items['dbscripts merge'] = array( + 'callback' => 'dbscripts_merge_drush', + 'description' => "Merge a development and production database together.", + ); + + $items['dbscripts find'] = array( + 'callback' => 'dbscripts_find_drush', + 'description' => "Find information about the database.", + ); + + $items['dbscripts increment'] = array( + 'callback' => 'dbscripts_raise_increments_drush', + 'description' => "Raise increments, and all tables that use it as a foreign key", + ); + + return $items; +} + +/** + * Implementation of hook_drush_help(). + * + * This function is called whenever a drush user calls + * 'drush help ' + * + * @param + * A string with the help section (prepend with 'drush:') + * + * @return + * A string with the help text for your command. + */ +function dbscripts_drush_help($section) { + switch ($section) { + case 'drush:dbscripts dump': + return dt(dbscripts_help('dump')); + + case 'drush:dbscripts restore': + return dt(dbscripts_help('restore')); + + case 'drush:dbscripts erase': + return dt(dbscripts_help('erase')); + + case 'drush:dbscripts merge': + return dt(dbscripts_help('merge')); + + case 'drush:dbscripts find': + return dt(dbscripts_help('find')); + + case 'drush:dbscripts raise_increments': + return dt(dbscripts_help('raise_increments')); + } +} + +/** + * Dump callback + */ +function dbscripts_dump_drush() { + $options = _dbscripts_get_options_drush(func_get_args()); + drush_print(dbscripts_dump($options['branch'], $options['filter'], $options['last-merge'])); +} + +/** + * Restore callback + */ +function dbscripts_restore_drush() { + $options = _dbscripts_get_options_drush(func_get_args()); + drush_print(dbscripts_restore($options['branch'],$options['filter'])); +} + +/** + * Erase callback + */ +function dbscripts_erase_drush() { + $options = _dbscripts_get_options_drush(func_get_args()); + drush_print(dbscripts_erase($options['filter'])); +} + +/** + * Merge callback + */ +function dbscripts_merge_drush() { + $options = _dbscripts_get_options_drush(func_get_args(), FALSE); + drush_print(dbscripts_merge($options)); +} + +/** + * Find callback + */ +function dbscripts_find_drush() { + $options = _dbscripts_get_options_drush(func_get_args(), FALSE); + drush_print(dbscripts_find($options)); +} + +/** + * Raise-Increments callback + */ +function dbscripts_raise_increments_drush() { + $options = _dbscripts_get_options_drush(func_get_args(), FALSE); + drush_print(dbscripts_raise_increments($options)); +} + +/** + * Helper function to convert args from drush into dbscripts.module args + */ +function _dbscripts_get_options_drush ($args, $get_defaults = TRUE) { + $options = array_unshift($args,'drush'); + return $get_defaults ? _dbscripts_get_options($options) : $options; +} + diff --exclude-from=/Users/jasonpkirst/.diffignore -N -urp ../dbscripts/dbscripts.module /Users/jasonpkirst/.drush/dbscripts/dbscripts.module --- ../dbscripts/dbscripts.module 2009-07-23 19:18:06.000000000 -0300 +++ /Users/jasonpkirst/.drush/dbscripts/dbscripts.module 2009-08-05 01:27:40.000000000 -0300 @@ -520,8 +520,26 @@ function dbscripts_restore($branch = 'de * Location of the database file that is used as 'production'. Only content * and user data will be perserved. All other data will be lost. */ -function dbscripts_merge($dev_branch = 'development', $lastmerge_branch = 'last-merge', $prod_branch = 'production', $continue = FALSE) { +function dbscripts_merge($argv) { require('config.inc'); + + $continue = FALSE; + if (in_array('continue', $argv)) { + $continue = TRUE; + } + + // Reset the array by removing the other set variables + foreach ($argv as $key => $variable) { + // The single = is in error, but doesn't work otherwise + if ($variable = 'continue') unset($argv[$key]); + } + foreach ($argv as $variable) { + $argv[] = $variable; + } + + $dev_db = isset($argv[1]) ? $argv[1] : FALSE; + $lastmerge_db = isset($argv[2]) ? $argv[2] : FALSE; + $prod_db = isset($argv[3]) ? $argv[3] : FALSE; // Ensure required files are loaded if (!isset($dump_path)) return "The file 'config.inc' does not exist. Copy from the example version?"; @@ -860,6 +878,113 @@ function dbscripts_merge($dev_branch = ' return "\nMerge was successfull.\n\n"; } +function dbscripts_find($options) { + + // Find all tables with auto_increment + if (isset($options[1]) && $options[1] == 'increment') { + $branch = isset($options[2]) ? $options[2] : 'development'; + $filter_option = isset($options[3]) ? $options[3] : 'full'; + $list = dbscripts_find_tables_with_increment($branch, $filter_option); + print_r($list); + + // Find all possible references to a given table + } elseif (isset($options[1]) && $options[1] == 'possible-references') { + $branch = isset($options[3]) ? $options[3] : 'development'; + $filter_option = isset($options[4]) ? $options[4] : 'full'; + + $list = array(); + if(isset($options[2]) && $options[2] != 'all') { + $table = $options[2]; + $list = dbscripts_find_possible_table_references($table, $branch, $filter_option); + } else { + print "\n Please wait. This can take awhile. 'ctrl+c' to cancel.\n\n"; + $table_list = dbscripts_find_tables_with_increment($branch, $filter_option); + if (is_array($table_list)) { + foreach ($table_list as $table) { + $references = dbscripts_find_possible_table_references($table, $branch, $filter_option); + if (is_array($references)) { + $list[$table] = $references; + } + } + } else { + // If not an array, pass through the error message + print "\n$table_list\n\n"; + } + } + print_r($list); + + // Find all configured and possible references to a given table + } elseif (isset($options[1]) && $options[1] == 'references') { + if(isset($options[2]) && $options[2] != 'all' && $options[2] != 'found') { + $table = $options[2]; + $branch = isset($options[3]) && $options[3] != 'found' ? $options[3] : 'development'; + $filter_option = isset($options[4]) && $options[4] != 'found' ? $options[4] : 'full'; + $found_only = in_array('found', $options) ? TRUE : FALSE; + $references = dbscripts_get_table_references($table, $branch, $filter_option); + + if (!$found_only) { + print_r($references); + } else { + if (isset($references['found'])) { + print_r($references['found']); + } else { + print "\nNo new references found for '$table'.\n\n"; + } + } + } else { + if (file_exists("$dump_path/development/table_list.txt")) { + print "\n Please wait. This can take awhile. 'ctrl+c' to cancel.\n\n"; + + $all_tables = file("$dump_path/development/table_list.txt", FILE_IGNORE_NEW_LINES); + $tables = _dbscripts_process_tables('development', array_merge($tables_filtered, $tables_filtered_l1, $tables_filtered_l2)); + foreach ($tables as $table) { + if (in_array('found', $options)) { + $table_references = dbscripts_get_table_references($table, 'development'); + if (isset($table_references['found'])) $references[$table] = $table_references['found']; + } else { + $table_references = dbscripts_get_table_references($table, 'development'); + if (is_array($table_references)) { + $references[$table] = $table_references; + } + } + } + if (isset($references)) { + print_r($references); + } else { + print "\nNo new references found.\n\n"; + } + } else { + print "\nMust provide a table to check.\n\n"; + } + + } + + // Fail + } else { + print "\nNot a valid search.\n\n"; + } + +} + +function dbscripts_raise_increments($options) { + + if (isset($options[1]) && $options[1] != 'all') { + if (isset($options[3])) { + $table = $options[1]; + $start_at = $options[2]; + $change_to = $options[3]; + $branch = isset($options[4]) ? $options[4] : 'development'; + $filter_option = isset($options[5]) ? $options[5] : 'full'; + + print dbscripts_raise_table_increments($table, $start_at, $change_to, $branch, $filter_option); + } else { + print "\n\nMust provide a table, increment to start at, and increment to change to\n\n"; + } + } else { + print dbscripts_raise_all_increments(); + } + +} /** diff --exclude-from=/Users/jasonpkirst/.diffignore -N -urp ../dbscripts/find.php /Users/jasonpkirst/.drush/dbscripts/find.php --- ../dbscripts/find.php 2009-07-23 19:18:06.000000000 -0300 +++ /Users/jasonpkirst/.drush/dbscripts/find.php 2009-08-05 00:41:31.000000000 -0300 @@ -5,90 +5,6 @@ if (in_array('help', $_SERVER['argv'])) { print dbscripts_help('find'); } else { - $options = $_SERVER['argv']; - - // Find all tables with auto_increment - if (isset($options[1]) && $options[1] == 'increment') { - $branch = isset($options[2]) ? $options[2] : 'development'; - $filter_option = isset($options[3]) ? $options[3] : 'full'; - $list = dbscripts_find_tables_with_increment($branch, $filter_option); - print_r($list); - - // Find all possible references to a given table - } elseif (isset($options[1]) && $options[1] == 'possible-references') { - $branch = isset($options[3]) ? $options[3] : 'development'; - $filter_option = isset($options[4]) ? $options[4] : 'full'; - - $list = array(); - if(isset($options[2]) && $options[2] != 'all') { - $table = $options[2]; - $list = dbscripts_find_possible_table_references($table, $branch, $filter_option); - } else { - print "\n Please wait. This can take awhile. 'ctrl+c' to cancel.\n\n"; - $table_list = dbscripts_find_tables_with_increment($branch, $filter_option); - if (is_array($table_list)) { - foreach ($table_list as $table) { - $references = dbscripts_find_possible_table_references($table, $branch, $filter_option); - if (is_array($references)) { - $list[$table] = $references; - } - } - } else { - // If not an array, pass through the error message - print "\n$table_list\n\n"; - } - } - print_r($list); - - // Find all configured and possible references to a given table - } elseif (isset($options[1]) && $options[1] == 'references') { - if(isset($options[2]) && $options[2] != 'all' && $options[2] != 'found') { - $table = $options[2]; - $branch = isset($options[3]) && $options[3] != 'found' ? $options[3] : 'development'; - $filter_option = isset($options[4]) && $options[4] != 'found' ? $options[4] : 'full'; - $found_only = in_array('found', $options) ? TRUE : FALSE; - $references = dbscripts_get_table_references($table, $branch, $filter_option); - - if (!$found_only) { - print_r($references); - } else { - if (isset($references['found'])) { - print_r($references['found']); - } else { - print "\nNo new references found for '$table'.\n\n"; - } - } - } else { - if (file_exists("$dump_path/development/table_list.txt")) { - print "\n Please wait. This can take awhile. 'ctrl+c' to cancel.\n\n"; - - $all_tables = file("$dump_path/development/table_list.txt", FILE_IGNORE_NEW_LINES); - $tables = _dbscripts_process_tables('development', array_merge($tables_filtered, $tables_filtered_l1, $tables_filtered_l2)); - foreach ($tables as $table) { - if (in_array('found', $options)) { - $table_references = dbscripts_get_table_references($table, 'development'); - if (isset($table_references['found'])) $references[$table] = $table_references['found']; - } else { - $table_references = dbscripts_get_table_references($table, 'development'); - if (is_array($table_references)) { - $references[$table] = $table_references; - } - } - } - if (isset($references)) { - print_r($references); - } else { - print "\nNo new references found.\n\n"; - } - } else { - print "\nMust provide a table to check.\n\n"; - } - - } - - // Fail - } else { - print "\nNot a valid search.\n\n"; - } + print dbscripts_find($_SERVER['argv']); } ?> \ No newline at end of file diff --exclude-from=/Users/jasonpkirst/.diffignore -N -urp ../dbscripts/merge.php /Users/jasonpkirst/.drush/dbscripts/merge.php --- ../dbscripts/merge.php 2009-07-23 19:18:06.000000000 -0300 +++ /Users/jasonpkirst/.drush/dbscripts/merge.php 2009-08-05 00:23:08.000000000 -0300 @@ -4,27 +4,7 @@ if (in_array('help', $_SERVER['argv'])) { print dbscripts_help('merge'); } else { - - // Findout if the user wants to continue from a previous merge - $continue = FALSE; - if (in_array('continue', $_SERVER['argv'])) { - $continue = TRUE; - } - - // Reset the array by removing the other set variables - foreach ($_SERVER['argv'] as $key => $variable) { - // The single = is in error, but doesn't work otherwise - if ($variable = 'continue') unset($_SERVER['argv'][$key]); - } - foreach ($_SERVER['argv'] as $variable) { - $_SERVER['argv'][] = $variable; - } - - $dev_db = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : FALSE; - $lastmerge_db = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : FALSE; - $prod_db = isset($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : FALSE; - - print dbscripts_merge($dev_db, $lastmerge_db, $prod_db, $continue); - + print dbscripts_merge($_SERVER['argv']); } + ?> diff --exclude-from=/Users/jasonpkirst/.diffignore -N -urp ../dbscripts/raise_increments.php /Users/jasonpkirst/.drush/dbscripts/raise_increments.php --- ../dbscripts/raise_increments.php 2009-07-23 19:18:06.000000000 -0300 +++ /Users/jasonpkirst/.drush/dbscripts/raise_increments.php 2009-08-05 01:09:14.000000000 -0300 @@ -4,22 +4,6 @@ if (in_array('help', $_SERVER['argv'])) { print dbscripts_help('raise_increments'); } else { - $options = $_SERVER['argv']; - - if (isset($options[1]) && $options[1] != 'all') { - if (isset($options[3])) { - $table = $options[1]; - $start_at = $options[2]; - $change_to = $options[3]; - $branch = isset($options[4]) ? $options[4] : 'development'; - $filter_option = isset($options[5]) ? $options[5] : 'full'; - - print dbscripts_raise_table_increments($table, $start_at, $change_to, $branch, $filter_option); - } else { - print "\n\nMust provide a table, increment to start at, and increment to change to\n\n"; - } - } else { - print dbscripts_raise_all_increments(); - } + print dbscripts_raise_increments($_SERVER['argv']); } ?> \ No newline at end of file