BundleTask::LoadById PHP Method

LoadById() public static method

public static LoadById ( integer $id ) : BundleTask
$id integer
return BundleTask
    public static function LoadById($id)
    {
        $db = \Scalr::getDb();
        $taskinfo = $db->GetRow("SELECT * FROM bundle_tasks WHERE id=?", array($id));
        if (!$taskinfo) {
            throw new Exception(sprintf(_("Bundle task ID#%s not found in database"), $id));
        }
        $task = new BundleTask($id);
        foreach (self::$FieldPropertyMap as $k => $v) {
            if (isset($taskinfo[$k])) {
                $task->{$v} = $taskinfo[$k];
            }
        }
        return $task;
    }

Usage Example

コード例 #1
0
ファイル: Bundletasks.php プロジェクト: scalr/scalr
 /**
  * @param   int     $bundleTaskId       ID of BundleTask
  * @param   string  $status   optional  Status of BundleTask
  * @param   bool    $taskInfo optional  Get updated information about task
  */
 public function xListLogsAction($bundleTaskId, $status = '', $taskInfo = false)
 {
     $task = BundleTask::LoadById($bundleTaskId);
     $this->user->getPermissions()->validate($task);
     $sql = "SELECT * FROM bundle_task_log WHERE bundle_task_id = ?";
     $response = $this->buildResponseFromSql2($sql, array('id', 'dtadded', 'message'), array(), array($bundleTaskId));
     foreach ($response["data"] as &$row) {
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row['dtadded']);
     }
     if ($taskInfo && $task->status != $status) {
         // status has been changed, also include information about task
         $row = $this->db->GetRow("SELECT b.*, (SELECT EXISTS (SELECT 1 FROM servers s WHERE s.server_id = b.server_id)) as server_exists FROM bundle_tasks b WHERE id = ?", [$task->id]);
         // temporary solution, refactor all on new model and replace this code
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row['dtadded']);
         if (!$row['bundle_type']) {
             $row['bundle_type'] = "*";
         }
         if ($row['dtfinished'] && $row['dtstarted']) {
             $row['duration'] = Scalr_Util_DateTime::getDateTimeDiff($row['dtfinished'], $row['dtstarted']);
         }
         if ($row['dtfinished']) {
             $row['dtfinished'] = Scalr_Util_DateTime::convertTz($row['dtfinished']);
         }
         if ($row['dtstarted']) {
             $row['dtstarted'] = Scalr_Util_DateTime::convertTz($row['dtstarted']);
         }
         $response['task'] = $row;
     }
     $this->response->data($response);
 }
All Usage Examples Of BundleTask::LoadById