public function cancelIntegrityCheck() { $version = $this->getVAVersion(); $version->published = false; $version->status = "init"; $version->save(); VMCaster::cancelIntegrityCheck($version->id); return true; }
public static function startIntegrityCheck($vaversionid) { $versions = new Default_Model_VAVersions(); $versions->filter->id->equals($vaversionid); if (count($versions->items) === 0) { return false; } $version = $versions->items[0]; $prevstatus = $version->status; //first cancel any running integrity check for this version VMCaster::cancelIntegrityCheck($vaversionid); $version->status = $prevstatus; $version->save(); if (!($version->published === false && $version->archived === false && ($version->status == "verifing" || $version->status == "verifingpublish") && $version->enabled === true)) { return false; } $url = VMCaster::getVMCasterUrl() . "/integrity/checkimagelist/" . $vaversionid . "/xml"; try { $xml = web_get_contents($url); if (trim($xml) === "") { throw new Exception('Could not connect to integrity check service. Please, try again later.'); } $result = VMCaster::parseIntegrityCheckResponse($xml); } catch (Exception $ex) { $result = VMCaster::parseIntegrityCheckResponse('[ERROR]' . $ex->getMessage()); if (intval($vaversionid) > 0) { VMCaster::cancelIntegrityCheck($vaversionid); } return $result; } $allimagesfailed = true; if ($result["status"] !== "success") { for ($i = 0; $i < count($result["images"]); $i += 1) { $image = $result["images"][$i]; if ($image["status"] === "error") { $instances = new Default_Model_VMIinstances(); $instances->filter->id->equals($image["id"]); if (count($instances->items) > 0) { $instance = $instances->items[0]; if ($instance->autointegrity == true) { $instance->integrityStatus = $image["status"]; } else { $instance->integrityStatus = "warning"; } $instance->integrityMessage = $image["http"]["message"]; //"Server responded with code: " . $image["http"]["code"]; $instance->save(); } } else { $allimagesfailed = false; } } } else { $allimagesfailed = false; } if ($allimagesfailed === true) { $version->status = 'failed'; } else { //'verifing'; } $needscheck = self::needsIntegrityCheck($version->id); if ($needscheck === false) { $version->status = 'verified'; } else { if ($version->status === 'verify') { $version->status = 'verifing'; } if ($version->status === 'verifypublish') { $version->status = 'verifingpublish'; } } $version->save(); return $result; }