Example #1
0
 /**
  * Install registries table
  *
  * @static
  * @access  protected
  * @return  void
  */
 public static function generate($table_name = null)
 {
     $table_name or $table_name = \Config::get('hybrid.tables.registry', 'options');
     $class_name = \Inflector::classify($table_name, true);
     if ('y' === \Cli::prompt("Would you like to install `registry.{$table_name}` table?", array('y', 'n'))) {
         Generate::migration(array('create_' . $table_name, 'name:string[255]', 'value:longtext'));
         Generate::$create_files = array();
     }
 }
Example #2
0
 /**
  * Execute all available migration
  *
  * @static
  * @access  protected
  * @return  void
  */
 protected static function execute()
 {
     if (empty(static::$queries)) {
         \Cli::write("Nothing to generate", "red");
     } elseif ('y' === \Cli::prompt("Confirm Generate Model and Migration?", array('y', 'n'))) {
         foreach (static::$queries as $data) {
             Generate::model($data);
             Generate::$create_files = array();
         }
     }
 }
Example #3
0
    /**
     * Writes a migration class to the filesystem
     * 
     * @param  string $up   PHP code to migrate up
     * @param  string $down PHP code to migrate down
     * @param  string $name The name of the migration, usually involving a timestamp
     * @return void
     */
    protected static function generateMigration($up = '', $down = '', $name = null)
    {
        // Get the migration name
        empty($name) and $name = 'Migration' . date('YmdHis');
        // Check if a migration with this name already exists
        if (($duplicates = glob(APPPATH . "migrations/*_{$name}*")) === false) {
            throw new \Exception("Unable to read existing migrations. Do you have an 'open_basedir' defined?");
        }
        if (count($duplicates) > 0) {
            // Don't override a file
            if (\Fuel::$is_cli && \Cli::option('s', \Cli::option('skip')) === true) {
                return;
            }
            // Tear up the file path and name to get the last duplicate
            $file_name = pathinfo(end($duplicates), PATHINFO_FILENAME);
            // Override the (most recent) migration with the same name by using its number
            if (\Fuel::$is_cli && \Cli::option('f', \Cli::option('force')) === true) {
                list($number) = explode('_', $file_name);
            } else {
                // Increment the name of this
                $name = \Str::increment(substr($file_name, 4), 2);
            }
        }
        $name = ucfirst(strtolower($name));
        $migration = <<<MIGRATION
<?php

namespace Fuel\\Migrations;

class {$name}
{
\tpublic function up()
\t{
{$up}
\t}

\tpublic function down()
\t{
{$down}
\t}
}
MIGRATION;
        $number = isset($number) ? $number : static::findMigrationNumber();
        $filepath = APPPATH . 'migrations/' . $number . '_' . strtolower($name) . '.php';
        Generate::create($filepath, $migration, 'migration');
        Generate::build();
    }