| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
require_once "phing/Task.php"; |
|---|
| 14 |
|
|---|
| 15 |
class installMidcomDir extends Task { |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
* The name of the module |
|---|
| 19 |
*/ |
|---|
| 20 |
private $module = null; |
|---|
| 21 |
|
|---|
| 22 |
* The path to install the module, should be set |
|---|
| 23 |
* in build properties |
|---|
| 24 |
*/ |
|---|
| 25 |
protected $install_dir = "/tmp"; |
|---|
| 26 |
|
|---|
| 27 |
public function setInstall_dir($str) { |
|---|
| 28 |
$this->install_dir = $str; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
* The setter for the attribute "project_dir" |
|---|
| 32 |
*/ |
|---|
| 33 |
protected $project_dir = null; |
|---|
| 34 |
|
|---|
| 35 |
public function setProject_dir($str) { |
|---|
| 36 |
$this->project_dir = $str; |
|---|
| 37 |
} |
|---|
| 38 |
protected $static_dir = null; |
|---|
| 39 |
public function setStatic_dir($dir) { |
|---|
| 40 |
$this->static_dir = $dir; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
* Umask for the dirs created. |
|---|
| 44 |
*/ |
|---|
| 45 |
protected $umask = 0777; |
|---|
| 46 |
public function setUmask($str) { |
|---|
| 47 |
$this->umask = $str; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
public function setModule($str) { |
|---|
| 51 |
$this->module = $str; |
|---|
| 52 |
} |
|---|
| 53 |
protected $schema_dir = ""; |
|---|
| 54 |
public function setSchema_dir($str) |
|---|
| 55 |
{ |
|---|
| 56 |
$this->schema_dir = $str; |
|---|
| 57 |
} |
|---|
| 58 |
protected $sql_dir = ""; |
|---|
| 59 |
public function setSql_dir($str) |
|---|
| 60 |
{ |
|---|
| 61 |
$this->sql_dir = $str; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
* The init method: Do init steps. |
|---|
| 65 |
*/ |
|---|
| 66 |
public function init() { |
|---|
| 67 |
|
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
* Create the projectdir and then make a symlink into the structure. |
|---|
| 72 |
*/ |
|---|
| 73 |
public function main() { |
|---|
| 74 |
if ($this->install_dir === null) { |
|---|
| 75 |
throw new Exception("Path must be set for this task to work!"); |
|---|
| 76 |
} |
|---|
| 77 |
$dirs = explode('.', $this->module); |
|---|
| 78 |
$module_dir = array_pop($dirs); |
|---|
| 79 |
$module_path = $this->install_dir . "/" . implode('/',$dirs); |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
if (!file_exists($module_path) && !mkdir ($module_path,0777, true)) { |
|---|
| 83 |
echo "Failed to create directory {$module_path}\n"; |
|---|
| 84 |
} |
|---|
| 85 |
$link = "{$module_path}/{$module_dir}"; |
|---|
| 86 |
$from = "{$this->project_dir}/{$this->module}"; |
|---|
| 87 |
$this->make_symlink($from,$link); |
|---|
| 88 |
|
|---|
| 89 |
$static = sprintf("%s/%s/static", $this->project_dir, $this->module); |
|---|
| 90 |
$link = sprintf("%s/%s",$this->static_dir, $this->module ); |
|---|
| 91 |
if (is_dir($static)) { |
|---|
| 92 |
$this->make_symlink($static, $link ); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
$module_name = str_replace( '.' , '_', $this->module ); |
|---|
| 96 |
$schema = sprintf("%s/%s/config/mgdschema.xml", $this->project_dir, $this->module); |
|---|
| 97 |
if (file_exists($schema)) |
|---|
| 98 |
{ |
|---|
| 99 |
echo "Symlinking schema {$schema} to " . $this->schema_dir . "/" . $module_name . ".xml\n"; |
|---|
| 100 |
$this->make_symlink($schema, $this->schema_dir . "/" . $module_name . ".xml"); |
|---|
| 101 |
} |
|---|
| 102 |
$schema_sql = sprintf("%s/%s/config/mgdschema.sql", $this->project_dir, $this->module); |
|---|
| 103 |
if (file_exists($schema_sql)) |
|---|
| 104 |
{ |
|---|
| 105 |
echo "Symlinking schema {$schema_sql} to " . $this->sql_dir . "/" . $module_name . ".sql\n"; |
|---|
| 106 |
$this->make_symlink($schema_sql, $this->sql_dir . "/" . $module_name . ".sql"); |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
* Creates a symlink to the file or directory |
|---|
| 113 |
* @param string paramname |
|---|
| 114 |
*/ |
|---|
| 115 |
private function make_symlink($from , $link, $debug = false) |
|---|
| 116 |
{ |
|---|
| 117 |
if (is_link($link)) |
|---|
| 118 |
{ |
|---|
| 119 |
return; |
|---|
| 120 |
} |
|---|
| 121 |
$command = sprintf("ln -s %s %s", $from, $link); |
|---|
| 122 |
$this->exec_command($command, $debug); |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
* Executes a given command. |
|---|
| 127 |
* @return none |
|---|
| 128 |
* @throws exception |
|---|
| 129 |
* @param string $command the command to be executed |
|---|
| 130 |
* @param boolean $debug set to true if you want to just se the |
|---|
| 131 |
* command to be executed. |
|---|
| 132 |
*/ |
|---|
| 133 |
private function exec_command($command, $debug = false) { |
|---|
| 134 |
if ($debug) { |
|---|
| 135 |
echo $command . "\n"; |
|---|
| 136 |
return; |
|---|
| 137 |
} |
|---|
| 138 |
$ret = ""; |
|---|
| 139 |
exec($command, & $output, $ret); |
|---|
| 140 |
if ($ret !== 0) |
|---|
| 141 |
{ |
|---|
| 142 |
throw new Exception("Exec of $command returned non zero code $ret"); |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
} |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
?> |
|---|