- $extension = basename(current(glob("modules/*.so")));
- $pattern = preg_quote($extension);
-
- foreach ($files as $index => $file) {
- $temp = new Tempfile("phpini");
- foreach (file($file) as $line) {
- if (preg_match("/^\s*extension\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) {
- // already there
- $this->info("Extension already activated\n");
- return;
- }
- fwrite($temp->getStream(), $line);
- }
- }
-
- // not found, add extension line to the last process file
- if (isset($temp, $file)) {
- fprintf($temp->getStream(), "extension=%s\n", $extension);
- $temp->closeStream();
-
- $path = $temp->getPathname();
- $stat = stat($file);
-
- try {
- $this->info("Running INI owner transfer ... ");
- $ugid = sprintf("%d:%d", $stat["uid"], $stat["gid"]);
- $cmd = new ExecCmd("chown", $this->args->verbose);
- if (isset($this->args->sudo)) {
- $cmd->setSu($this->args->sudo);
- }
- $cmd->run([$ugid, $path]);
- $this->info("OK\n");
-
- $this->info("Running INI permission transfer ... ");
- $perm = decoct($stat["mode"] & 0777);
- $cmd = new ExecCmd("chmod", $this->args->verbose);
- if (isset($this->args->sudo)) {
- $cmd->setSu($this->args->sudo);
- }
- $cmd->run([$perm, $path]);
- $this->info("OK\n");
-
- $this->info("Running INI activation ... ");
- $cmd = new ExecCmd("mv", $this->args->verbose);
- if (isset($this->args->sudo)) {
- $cmd->setSu($this->args->sudo);
- }
- $cmd->run([$path, $file]);
- $this->info("OK\n");
- } catch (\Exception $e) {
- $this->error("%s\n", $e->getMessage());
- $this->error("%s\n", $cmd->getOutput());
- exit(5);
+ $sudo = isset($this->args->sudo) ? $this->args->sudo : null;
+ $type = $this->metadata("type") ?: "php";
+
+ try {
+ $this->info("Running INI activation ...\n");
+ $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo);
+ if (!$activate->run($this->args->verbose)) {
+ $this->info("Extension already activated ...\n");