示例#1
0
 function fixtures($args = array())
 {
     if (substr($this->CI->db->database, -5, 5) != '_test') {
         die("\nSorry, the name of your test database must end on '_test'.\n" . "This prevents deleting important data by accident.\n");
     }
     //$this->CI->db->database = preg_replace("#_test$#", "_development", $this->CI->db->database);
     if (!$this->CI->db->db_select()) {
         die("\nCould not select development database.\n");
     }
     $opts = getopts(array('rows' => array('switch' => 'n', 'type' => GETOPT_VAL, 'default' => 5), 'fixtures' => array('switch' => 'f', 'type' => GETOPT_MULTIVAL), 'output' => array('switch' => 'o', 'type' => GETOPT_VAL, 'default' => '/fixtures')), $args);
     $rows = $opts['rows'];
     $fixtures = $opts['fixtures'];
     $output = rtrim(str_replace('\\', '/', $opts['output']), '/') . '/';
     if (!@chdir(dirname(__FILE__) . '/' . $output)) {
         die("\nOutput directory '{$output}' does not exist.\n");
     }
     $tables = $this->CI->db->list_tables();
     if (count($fixtures) == 0) {
         $fixtures = $tables;
     } else {
         /* check tables */
         foreach ($fixtures as $fixture) {
             if (!in_array($fixture, $tables)) {
                 die("\nTable `{$fixture}` does not exist.\n");
             }
         }
     }
     foreach ($fixtures as $fixture) {
         $filename = $fixture . '_fixt.yml';
         $data = $this->get_table_data($fixture, $rows);
         $yaml_data = CIUnit::$spyc->dump($data);
         $yaml_data = preg_replace('#^\\-\\-\\-#', '', $yaml_data);
         /* don't check if the file already exists */
         file_put_contents($filename, $yaml_data);
     }
 }
示例#2
0
文件: CoreTest.php 项目: ejz/core
 public function testGetopts()
 {
     $opts = getopts(array('c' => false, 'b' => false, 'a' => false, 'long-arg' => false, 'long-arg-2' => true, 'long-arg-3' => true), explode(' ', './execute -abc arg --long-arg --long-arg-2 arg2 --long-arg-3=arg3 final'));
     $this->assertEquals('./execute', $opts[0]);
     $this->assertEquals('arg', $opts[1]);
     $this->assertEquals(true, $opts['c']);
     $this->assertEquals(true, $opts['b']);
     $this->assertEquals(true, $opts['a']);
     $this->assertEquals(true, $opts['long-arg']);
     $this->assertEquals('arg2', $opts['long-arg-2']);
     $this->assertEquals('arg3', $opts['long-arg-3']);
     $this->assertEquals('final', $opts[2]);
     //
     $opts = getopts(array('a' => false, 'F' => true, 'b' => true, 'c' => false), explode(' ', './execute -a mmm -F fff'));
     $this->assertEquals('fff', $opts['F']);
     $this->assertTrue($opts['a']);
     $this->assertTrue(!isset($opts['b']));
     $this->assertTrue(!isset($opts['c']));
     //
     $opts = getopts(array(), explode(' ', './execute -a final'));
     $this->assertEquals(array(), $opts);
     //
     $opts = getopts(array(), explode(' ', './execute --long final'));
     $this->assertEquals(array(), $opts);
     //
     $opts = getopts(array('a' => true), explode(' ', './execute -a1'));
     $this->assertEquals(1, $opts['a']);
     //
     $opts = getopts(array('a' => true, 'b' => false), explode(' ', './execute -ba 1'));
     $this->assertEquals(array(), $opts);
     //
     $opts = getopts(array('long' => false), explode(' ', './execute --long=1'));
     $this->assertEquals(array(), $opts);
     //
     $opts = getopts(array(), explode(' ', './execute --long'));
     $this->assertEquals(array(), $opts);
     //
     $opts = getopts(array('a' => true), array('./execute', '-a '));
     $this->assertEquals(" ", $opts['a']);
     //
     $opts = getopts(array('r' => true), array('./execute', '-r', "//text()"));
     $this->assertEquals("//text()", $opts['r']);
 }
示例#3
0
i - indexes
d - table data
r - references
v - views
p - procedures
tr- triggers
g - permission grants
TXT
), 'user-handling' => array('switch' => array('user-handling'), 'type' => GETOPT_VAL, 'default' => 'check', 'help' => '(check|create|with-password|skip|only-list) how to restore user accounts'), 'create-index' => array('switch' => array('create-index'), 'type' => GETOPT_VAL, 'default' => 'before', 'help' => '(before|after) data load'), 'filter-ext' => array('switch' => array('F', 'filter-ext'), 'type' => GETOPT_VAL, 'help' => 'external command which returns 1 if object action should be processes'), 'clone-to' => array('switch' => array('C', 'clone-to'), 'type' => GETOPT_VAL, 'help' => 'provide folder where you want to copy backup data, filter will be applied, if value ends with zip data will be compressed'), 'decompress-only' => array('switch' => array('do', 'decompress-only'), 'type' => GETOPT_SWITCH, 'help' => 'decompress data files only'), 'decompress-method' => array('switch' => array('decompress-method'), 'type' => GETOPT_VAL, 'default' => 'php-gz', 'help' => '(php-gz=internal PHP zlib, gunzip=system utility) decompress data files only'), 'decompress-folder' => array('switch' => array('df', 'decompress-folder'), 'type' => GETOPT_VAL, 'help' => 'if data have to be uncompressed it will happen into data folder, you may change this with this option'), 'decompress-action' => array('switch' => array('da', 'decompress-action'), 'type' => GETOPT_VAL, 'default' => 'delete', 'help' => <<<TXT
if data had to be decompressed on import this will happen after import completes:
\tdelete - delete decompressed
\tkeep - keep decompressed and compressed
\treplace - keep decompressed and delete compressed
TXT
), 'remove-files' => array('switch' => array('remove-files'), 'type' => GETOPT_VAL, 'help' => '(csv=decompressed data files|z=compressed data files) data load, for security reason you have to add ^ before value to physically remove files'), 'force' => array('switch' => array('f', 'force'), 'type' => GETOPT_SWITCH, 'help' => 'will not prompt user to approve restore'), 'quite' => array('switch' => array('q', 'quite'), 'type' => GETOPT_SWITCH, 'help' => 'will not print messages'), 'log-process' => array('switch' => array('log-process'), 'type' => GETOPT_VAL, 'default' => 1, 'help' => 'print messages describing restore process (0=off, 1=on)'), 'log-sql-warn' => array('switch' => array('log-sql-warn'), 'type' => GETOPT_VAL, 'default' => 1, 'help' => 'print MySQL server warning messages (0=off, 1=on)'), 'log-sql-exec' => array('switch' => array('log-sql-exec'), 'type' => GETOPT_VAL, 'default' => 2, 'help' => 'print executed SQL statements (0=off, 1=all, 2=if SQL warning found)'), 'help' => array('switch' => array('?', 'help'), 'type' => GETOPT_SWITCH, 'help' => 'display instruction how to use cli.php'));
    $opts = getopts($options, $_SERVER['argv']);
} catch (Exception $e) {
    help($options);
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
    exit;
}
if ($opts['help']) {
    // show help message and exit
    help($options);
    exit;
}
$folder = "";
if (count($opts['cmdline']) != 1) {
    help($options, "ERROR: you have to specify backup directory");
    exit(RestoreMysql::RETCODE_PARAM_ERROR);
} else {
示例#4
0
文件: GetOpts.php 项目: martinsv/bart
 public static function parse($options, $fromarr = null)
 {
     return getopts($options, $fromarr);
 }