Airship\Cabin\Bridge\Blueprint\Skyport::forceRemoval PHP Method

forceRemoval() public method

Force a package to be removed.
public forceRemoval ( string $type, string $supplier, string $package ) : string
$type string
$supplier string
$package string
return string
    public function forceRemoval(string $type, string $supplier, string $package) : string
    {
        $packageInfo = $this->getDetails($type, $supplier, $package);
        if (empty($packageInfo)) {
            throw new \Exception(\__('Package not found!'));
        }
        if (!$packageInfo['installed']) {
            return 'Package is not installed.';
        }
        $return = "Package {$supplier}/{$package} ({$type}) found." . " Proceeding with removal.\n";
        switch ($type) {
            case 'Cabin':
                $return .= $this->removeCabin($packageInfo);
                break;
            case 'Gadget':
                $return .= $this->removeGadget($packageInfo);
                break;
            case 'Motif':
                $return .= $this->removeMotif($packageInfo);
                break;
        }
        $this->db->beginTransaction();
        $this->db->update('airship_package_cache', ['installed' => false], ['packageid' => $packageInfo['packageid']]);
        if ($this->db->commit()) {
            $return .= "Removed successfully.";
        }
        return $return;
    }

Usage Example

Esempio n. 1
0
 /**
  * Trigger the package uninstall process.
  */
 public function removePackage()
 {
     $expected = ['package', 'supplier', 'type'];
     if (!\Airship\all_keys_exist($expected, $_POST)) {
         \Airship\json_response(['status' => 'ERROR', 'message' => \__('Incomplete request.')]);
     }
     if ($this->skyport->isLocked()) {
         $locked = true;
         if ($this->skyport->isPasswordLocked() && !empty($_POST['password'])) {
             $password = new HiddenString($_POST['password']);
             if ($this->skyport->tryUnlockPassword($password)) {
                 $_SESSION['airship_install_lock_override'] = true;
                 $locked = false;
             }
             unset($password);
         }
         if ($locked) {
             if ($this->skyport->isPasswordLocked()) {
                 \Airship\json_response(['status' => 'PROMPT', 'message' => \__('The skyport is locked. To unlock the skyport, please provide the password.')]);
             }
             \Airship\json_response(['status' => 'ERROR', 'message' => \__('The skyport is locked. You cannot install packages from the web interface.')]);
         }
     }
     try {
         $filter = new SkyportFilter();
         $post = $filter($_POST);
     } catch (\TypeError $ex) {
         $this->log("Input violation", LogLevel::ALERT, \Airship\throwableToArray($ex));
         \Airship\json_response(['status' => 'ERROR', 'message' => 'Type Error']);
         return;
     }
     $output = $this->skyport->forceRemoval($post['type'], $post['supplier'], $post['package']);
     \Airship\json_response(['status' => 'OK', 'message' => $output]);
 }