/** * test camelcase */ public function test_camelcase() { $a = "add index to users"; $this->assertEquals('AddIndexToUsers', Ruckusing_Util_Naming::camelcase($a)); $b = "add index to Users"; $this->assertEquals('AddIndexToUsers', Ruckusing_Util_Naming::camelcase($b)); $c = "AddIndexToUsers"; $this->assertEquals('AddIndexToUsers', Ruckusing_Util_Naming::camelcase($c)); }
/** * Primary task entry point * * @param array $args The current supplied options. */ public function execute($args) { $output = ''; // Add support for old migration style if (!is_array($args) || !array_key_exists('name', $args)) { $cargs = $this->parse_args($_SERVER['argv']); //input sanity check if (!is_array($cargs) || !array_key_exists('name', $cargs)) { $output .= $this->help(); return $output; } $migration_name = $cargs['name']; } else { $migration_name = $args['name']; } if (!array_key_exists('module', $args)) { $args['module'] = ''; } //clear any filesystem stats cache clearstatcache(); $framework = $this->get_framework(); $migrations_dir = $framework->migrations_directory($args['module']); if (!is_dir($migrations_dir)) { $output .= "\n\tMigrations directory (" . $migrations_dir . " doesn't exist, attempting to create.\n"; if (mkdir($migrations_dir, 0755, true) === FALSE) { $output .= "\n\tUnable to create migrations directory at " . $migrations_dir . ", check permissions?\n"; } else { $output .= "\n\tCreated OK\n"; } } //generate a complete migration file $next_version = Ruckusing_Util_Migrator::generate_timestamp(); $class = Ruckusing_Util_Naming::camelcase($migration_name); if (!self::classNameIsCorrect($class)) { throw new Ruckusing_Exception("Bad migration name,PHP class can't be named as {$class}.Please, choose another name.", Ruckusing_Exception::INVALID_ARGUMENT); } $all_dirs = $framework->migrations_directories(); if ($re = self::classNameIsDuplicated($class, $all_dirs)) { throw new Ruckusing_Exception("This migration name is already used in the \"{$re}\" directory. Please, choose another name.", Ruckusing_Exception::INVALID_ARGUMENT); } $file_name = $next_version . '_' . $class . '.php'; //check to make sure our destination directory is writable if (!is_writable($migrations_dir)) { throw new Ruckusing_Exception("ERROR: migration directory '" . $migrations_dir . "' is not writable by the current user. Check permissions and try again.", Ruckusing_Exception::INVALID_MIGRATION_DIR); } //write it out! $full_path = $migrations_dir . DIRECTORY_SEPARATOR . $file_name; $template_str = self::get_template($class); $file_result = file_put_contents($full_path, $template_str); if ($file_result === FALSE) { throw new Ruckusing_Exception("Error writing to migrations directory/file. Do you have sufficient privileges?", Ruckusing_Exception::INVALID_MIGRATION_DIR); } else { $output .= "\n\tCreated migration: {$file_name}\n\n"; } return $output; }