DNEnvironment::create_from_path PHP Method

create_from_path() public static method

Used by the sync task
public static create_from_path ( string $path ) : DNEnvironment
$path string
return DNEnvironment
    public static function create_from_path($path)
    {
        $e = DNEnvironment::create();
        $e->Filename = $path;
        $e->Name = basename($e->Filename, '.rb');
        // add each administrator member as a deployer of the new environment
        $adminGroup = Group::get()->filter('Code', 'administrators')->first();
        $e->DeployerGroups()->add($adminGroup);
        return $e;
    }

Usage Example

コード例 #1
0
 /**
  * Sync the in-db project list with a list of file paths
  * @param array $paths Array of pathnames
  * @param boolean $remove Should obsolete environments be removed?
  */
 public function syncWithPaths($paths, $dryRun = false)
 {
     // Normalise paths in DB
     foreach ($this as $item) {
         $real = realpath($item->Filename);
         if ($real && $real != $item->Filename) {
             $item->Filename = $real;
             $item->write();
         }
     }
     foreach ($paths as $path) {
         $path = basename($path);
         if ($this->filter('Filename', $path)->count()) {
             continue;
         }
         $this->message('Adding "' . basename($path) . '" to db');
         if (!$dryRun) {
             $environment = DNEnvironment::create_from_path($path);
             $environment->ProjectID = $this->projectID;
             $environment->write();
         }
     }
 }