/**
  * Constructor for this ApplicationUpdater.
  * 
  * @return \sfAltumoPlugin\Deployment\ApplicationUpdater
  */
 public function __construct($project_root)
 {
     if (!file_exists($project_root)) {
         throw new \Exception('Directory: ' . $project_root . ' does not exist or is not readable.');
     }
     $subdirs = \Altumo\Utils\Finder::type('dir')->maxdepth(0)->relative()->in($project_root);
     if (!in_array('htdocs', $subdirs)) {
         throw new \Exception('Project root must have an htdocs subdirectory.');
     }
     $this->setProjectRoot($project_root);
 }
Beispiel #2
0
 /**
  * Runs all of the unit tests in the suppied directory (and all of the 
  * subdirectories).
  * 
  * @param string $test_directory
  */
 protected function runTests($test_directory)
 {
     $files = \Altumo\Utils\Finder::type('file')->name('*Test.php')->in($test_directory);
     foreach ($files as $file) {
         //determine the class name
         $class_name = '\\Altumo\\Test\\' . basename($file, '.php');
         //skip the base class
         if ($class_name == '\\Altumo\\Test\\UnitTest') {
             continue;
         }
         //include the file
         require_once $file;
         //display which unit test is being run
         $this->output("\n" . $file . ':');
         //instantiate and run the unit test
         $unit_test = new $class_name($this);
         if (method_exists($unit_test, 'setup')) {
             $unit_test->setup();
         }
         if (method_exists($unit_test, 'run')) {
             $unit_test->run();
         } else {
             $methods = get_class_methods($class_name);
             foreach ($methods as $method) {
                 if (preg_match('/^test(.*?)$/', $method, $regs)) {
                     $test_name = $regs[1];
                     $this->output("\n\t" . $test_name . ':');
                     $unit_test->{$method}();
                 }
             }
         }
         if (method_exists($unit_test, 'tearDown')) {
             $unit_test->tearDown();
         }
         $this->output("\n");
     }
     $this->displayReport();
 }
    /**
     * @see sfTask
     */
    protected function execute($arguments = array(), $options = array())
    {
        //sfAltumoPlugin tests
        //$test_suite = new \Altumo\Test\TestSuite( __DIR__ . '/../../test' );
        //Project tests
        //$test_suite = new \Altumo\Test\TestSuite( __DIR__ . '/../../../../test' );
        //get the project root and set the template variables
        $project_root = realpath(sfConfig::get('sf_root_dir') . '/../../');
        $domain_name = $arguments['domain'];
        $create_database_temp_file = sfConfig::get('sf_root_dir') . '/create_database.sql';
        $template_variables = array('PROJECT_ROOT' => $project_root, 'PROJECT_DOMAIN' => $domain_name, 'DATABASE_HOST' => $arguments['database-host'], 'DATABASE_USER' => $arguments['database-user'], 'DATABASE_PASSWORD' => $arguments['database-password'], 'DATABASE' => $arguments['database'], 'ENVIRONMENT' => $arguments['environment']);
        //fixes the file and directory permissions
        //set the default symfony permissions with the symfony task
        `./symfony project:permissions`;
        $this->log('Symfony permissions set.');
        //make apache logs folder writable
        chmod($project_root . '/htdocs/logs', 0777);
        $this->log('Apache log file permissions set.');
        //setup the database builders
        `./symfony altumo:update-database init`;
        $this->log('Database updater initialized.');
        //untemplates the templated files
        $template_path = $project_root . '/htdocs/project/plugins/sfAltumoPlugin/install';
        $templated_files = array(array('source' => $template_path . '/' . 'databases.yml.tpl', 'destination' => sfConfig::get('sf_config_dir') . '/databases.yml'), array('source' => $template_path . '/' . 'propel.ini.tpl', 'destination' => sfConfig::get('sf_config_dir') . '/propel.ini'), array('source' => $template_path . '/' . 'index.php.tpl', 'destination' => sfConfig::get('sf_web_dir') . '/index.php'), array('source' => $template_path . '/' . 'api.php.tpl', 'destination' => sfConfig::get('sf_web_dir') . '/api.php'), array('source' => $template_path . '/' . 'vhost.tpl', 'destination' => sfConfig::get('sf_root_dir') . '/' . $domain_name), array('source' => $template_path . '/' . 'create_database.sql.tpl', 'destination' => $create_database_temp_file), array('source' => sfConfig::get('sf_data_dir') . '/' . 'updater-configuration.xml', 'destination' => sfConfig::get('sf_data_dir') . '/' . 'updater-configuration.xml'));
        foreach ($templated_files as $templated_file) {
            $template_file_contents = file_get_contents($templated_file['source']);
            foreach ($template_variables as $variable_name => $value) {
                $template_file_contents = str_replace('[[' . $variable_name . ']]', $value, $template_file_contents);
            }
            file_put_contents($templated_file['destination'], $template_file_contents);
        }
        $this->log('Template files installed.');
        //install build sequence file
        $filename = sfConfig::get('sf_data_dir') . '/' . 'build-sequence.xml';
        $contents = <<<BUILD_SEQUENCE
<?xml version="1.0" encoding="UTF-8"?>
<BuildSequence>
</BuildSequence>
BUILD_SEQUENCE;
        if (!file_exists($filename)) {
            file_put_contents($filename, $contents);
        }
        //install git hooks
        `./symfony altumo:git-hook-handler install`;
        $this->log('Git hooks installed.');
        //display the next steps to take
        //get the next number available in /etc/apache2/sites-enabled
        $next_available_sites_enabled = 0;
        $files = \Altumo\Utils\Finder::type('file')->follow_link()->relative()->in('/etc/apache2/sites-enabled');
        foreach ($files as $file) {
            if (preg_match('/^(\\d+)/', $file, $regs)) {
                $new_number = (int) $regs[1];
                if ($new_number > $next_available_sites_enabled) {
                    $next_available_sites_enabled = $new_number;
                }
            }
        }
        $next_available_sites_enabled++;
        $next_available_sites_enabled = str_pad($next_available_sites_enabled, 3, "0", STR_PAD_LEFT);
        //get the database script
        $database_script = file_get_contents($create_database_temp_file);
        unlink($create_database_temp_file);
        //indent it
        $database_script = preg_replace('/^/m', '            ', $database_script);
        $next_steps = <<<STEPS
            
    NEXT STEPS:
    
        //install the vhost 
            sudo cp {$domain_name} /etc/apache2/sites-available
            sudo ln -s /etc/apache2/sites-available/{$domain_name} /etc/apache2/sites-enabled/{$next_available_sites_enabled}-{$domain_name}
            rm {$domain_name}
            sudo /etc/init.d/apache2 restart
            
        //create the database and user
{$database_script}
            
        //register domain and point to dns servers    
        //setup dns entries (or hosts file entries)

        ./symfony altumo:test-environment
        ./symfony cc
        ./symfony altumo:update-environment
        
        //if this is a dev environment, you may want to set debug to true
        //in both the api.php and index.php controllers in the web folder
        
        //add all of the changed files to git (everything else should already be ignored)
            
STEPS;
        echo $next_steps . "\n";
    }
 /**
  * Gets an array of sql files to move to the appropriate directories.
  * Files must be in the data/new folder AND be in the current commit to qualify for being moved.
  * 
  * @param string $commit_hash
  * @return array
  */
 protected function getFilesToMove($commit_hash)
 {
     $database_dir = $this->getDatabaseDirectory();
     $sql_files_in_filesystem = \Altumo\Utils\Finder::type('file')->name('/\\.(sql|php)$/')->in($database_dir . '/new');
     $sql_files_in_commit = $this->getNewDatabaseFilesByCommit($commit_hash);
     $move_sql_files = array();
     foreach ($sql_files_in_filesystem as $sql_file_in_filesystem) {
         if (in_array($sql_file_in_filesystem, $sql_files_in_commit)) {
             $move_sql_files[] = $sql_file_in_filesystem;
         }
     }
     return $move_sql_files;
 }
 /**
  * Returns an array of paths to schema.base.xml paths to be processed.
  * 
  * @returns array           // of string (paths)
  */
 public static function getSchemaFilePaths()
 {
     $schema_files = \Altumo\Utils\Finder::type('file')->name('*schema.xml')->in(__DIR__ . '/../../../../config/', __DIR__ . '/../../config/');
     return $schema_files;
 }