- $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);
-
- $ugid = sprintf("%d:%d", $stat["uid"], $stat["gid"]);
- $this->exec("INI owner transfer", "chown", [$ugid, $path], true);
-
- $perm = decoct($stat["mode"] & 0777);
- $this->exec("INI permission transfer", "chmod", [$perm, $path], true);
-
- $this->exec("INI activation", "mv", [$path, $file], true);
+ $sudo = isset($this->args->sudo) ? $this->args->sudo : null;
+ $type = $this->metadata("type") ?: "extension";
+
+ $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo);
+ if (!$activate->run($this->verbosity())) {
+ $this->info("Extension already activated ...\n");