BundleTask::Save PHP Method

Save() public method

public Save ( )
    function Save()
    {
        $row = $this->Unbind();
        unset($row['id']);
        // Prepare SQL statement
        $set = array();
        $bind = array();
        foreach ($row as $field => $value) {
            $set[] = "`{$field}` = ?";
            $bind[] = $value;
        }
        $set = join(', ', $set);
        try {
            // Perform Update
            $bind[] = $this->id;
            $this->Db->Execute("UPDATE bundle_tasks SET {$set} WHERE id = ?", $bind);
        } catch (Exception $e) {
            throw new Exception("Cannot save bundle task. Error: " . $e->getMessage(), $e->getCode());
        }
    }

Usage Example

コード例 #1
0
ファイル: class.DBRole.php プロジェクト: mheydt/scalr
 public static function createFromBundleTask(BundleTask $BundleTask)
 {
     $db = \Scalr::getDb();
     $DBServer = DBServer::LoadByID($BundleTask->serverId);
     if ($BundleTask->prototypeRoleId) {
         $proto_role = $db->GetRow("SELECT * FROM roles WHERE id=? LIMIT 1", array($BundleTask->prototypeRoleId));
         if (!$proto_role['architecture']) {
             $proto_role['architecture'] = $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE);
         }
     } else {
         $behaviors = array_unique(explode(',', $DBServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR)));
         sort($behaviors);
         $proto_role = array("behaviors" => join(',', $behaviors), "architecture" => $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE), "name" => "*import*");
     }
     if (!$proto_role['architecture']) {
         $proto_role['architecture'] = 'x86_64';
     }
     if (!$BundleTask->cloudLocation) {
         if ($DBServer) {
             $BundleTask->cloudLocation = $DBServer->GetCloudLocation();
         }
     }
     $osId = $BundleTask->osId;
     $meta = $BundleTask->getSnapshotDetails();
     if (!$osId) {
         if ($proto_role) {
             $osId = $proto_role['os_id'];
         } elseif ($meta['os'] && $meta['os']->version) {
             /*
                             if ($meta['os']->version == '2008Server') {
                                 $osInfo->name = 'Windows 2008 Server';
                                 $osInfo->family = 'windows';
                                 $osInfo->generation = '2008';
                                 $osInfo->version = '2008Server';
                             } elseif ($meta['os']->version == '2008ServerR2') {
                                 $osInfo->name = 'Windows 2008 Server R2';
                                 $osInfo->family = 'windows';
                                 $osInfo->generation = '2008';
                                 $osInfo->version = '2008ServerR2';
                             }*/
             //TODO:
         }
     }
     if ($proto_role['cat_id']) {
         $catId = $proto_role['cat_id'];
     } else {
         $catId = ROLE_BEHAVIORS::GetCategoryId($proto_role['behaviors']);
     }
     $db->Execute("INSERT INTO roles SET\n            name\t\t\t= ?,\n            origin\t\t\t= ?,\n            dtadded         = NOW(),\n            client_id\t\t= ?,\n            env_id\t\t\t= ?,\n            cat_id          = ?,\n            description\t\t= ?,\n            behaviors\t\t= ?,\n            generation\t\t= ?,\n            added_by_email  = ?,\n            added_by_userid = ?,\n            os_id\t\t\t= ?\n        ", array($BundleTask->roleName, ROLE_TYPE::CUSTOM, $BundleTask->clientId, $BundleTask->envId, $catId, $BundleTask->description, $proto_role['behaviors'], 2, $BundleTask->createdByEmail, $BundleTask->createdById, $osId));
     $role_id = $db->Insert_Id();
     $BundleTask->roleId = $role_id;
     $BundleTask->Save();
     $BundleTask->Log(sprintf("Created new role. Role name: %s. Role ID: %s", $BundleTask->roleName, $BundleTask->roleId));
     $role = self::loadById($role_id);
     $behaviors = explode(",", $proto_role['behaviors']);
     foreach ($behaviors as $behavior) {
         $db->Execute("INSERT IGNORE INTO role_behaviors SET\n                role_id\t\t\t= ?,\n                behavior\t\t= ?\n            ", array($role_id, $behavior));
     }
     // Set image
     $role->__getNewRoleObject()->setImage($BundleTask->platform, $BundleTask->cloudLocation, $BundleTask->snapshotId, $BundleTask->createdById, $BundleTask->createdByEmail);
     // Set params
     if ($proto_role['id']) {
         $dbSecRules = $db->GetAll("SELECT * FROM role_security_rules WHERE role_id = ?", array($proto_role['id']));
         foreach ($dbSecRules as $dbSecRule) {
             $db->Execute("INSERT INTO role_security_rules SET role_id = ?, rule = ?", array($role_id, $dbSecRule['rule']));
         }
         $props = $db->GetAll("SELECT * FROM role_properties WHERE role_id=?", array($proto_role['id']));
         foreach ($props as $prop) {
             $role->setProperty($prop['name'], $prop['value']);
         }
         $scripts = $db->GetAll("SELECT * FROM role_scripts WHERE role_id=?", array($proto_role['id']));
         foreach ($scripts as &$script) {
             $script['params'] = unserialize($script['params']);
         }
         $role->setScripts($scripts);
         $variables = new Scalr_Scripting_GlobalVariables($BundleTask->clientId, $proto_role['env_id'], ScopeInterface::SCOPE_ROLE);
         $variables->setValues($variables->getValues($proto_role['id']), $role->id);
     }
     $role->syncAnalyticsTags();
     return $role;
 }
All Usage Examples Of BundleTask::Save