public function xRemoveAction(JsonData $images, $removeFromCloud = false)
{
$this->request->restrictAccess('IMAGES', 'MANAGE');
$errors = [];
$processed = [];
$pending = [];
foreach ($images as $hash) {
try {
/* @var $im Image */
$im = Image::findPk($hash);
if ($im) {
$this->request->checkPermissions($im, true);
if (!$im->getUsed()) {
if ($removeFromCloud && $this->user->isUser() && $im->platform != SERVER_PLATFORMS::AZURE) {
if ($im->isUsedGlobal()) {
throw new Exception(sprintf("Unable to delete %s, this Image may be:\n- Still registered in another Environment or Account\n- Currently in-use by a Server in another Environment", $im->id));
}
$im->status = Image::STATUS_DELETE;
$im->save();
$pending[] = $im->hash;
} else {
if ($this->user->isScalrAdmin() && $im->isUsedGlobal()) {
throw new Exception(sprintf("Unable to delete %s, this Image may be:\n- Still registered in another Environment or Account\n- Currently in-use by a Server in another Environment", $im->id));
}
$im->delete();
$processed[] = $im->hash;
}
}
}
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
}
$this->response->data(['processed' => $processed, 'pending' => $pending]);
if (count($errors)) {
$this->response->warning("Images(s) successfully removed, but some errors occurred:\n" . implode("\n", $errors));
} else {
$this->response->success('Images(s) successfully removed');
}
}