Core class updates

Improved database abstraction class to support insert and select queries
in various forms.
Added classes for pulling log entries back out of the database.
Updated Job class to describe a known job in the database, and added
JobStatus to track status updates on jobs.
Updated Config class to connect to the database, and load all settings
on startup.
Improved the class autoloader to support Exceptions in a single file as
a special case, and added this file.
This commit is contained in:
2010-03-18 02:00:53 +00:00
parent 3603445a5b
commit a9ebf6e0cb
11 changed files with 541 additions and 9 deletions

View File

@@ -3,15 +3,127 @@
class HandBrakeCluster_Job {
private $id;
private $name;
private $source;
private $destination;
private $title;
private $format;
private $video_codec;
private $video_width;
private $video_height;
private $quantizer;
private $deinterlace;
private $audio_tracks;
private $audio_codecs;
private $audio_names;
private $subtitle_tracks;
public function __construct($id) {
$this->id = $id;
private $statuses = null;
public function __construct($id, $name, $source, $destination, $title, $format, $video_codec, $video_width, $video_height, $quantizer, $deinterlace, $audio_tracks, $audio_codecs, $audio_names, $subtitle_tracks) {
$this->id = $id;
$this->name = $name;
$this->source = $source;
$this->destination = $destination;
$this->title = $title;
$this->format = $format;
$this->video_codec = $video_codec;
$this->video_width = $video_width;
$this->video_height = $video_height;
$this->quantizer = $quantizer;
$this->deinterlace = $deinterlace;
$this->audio_tracks = $audio_tracks;
$this->audio_codecs = $audio_codecs;
$this->audio_names = $audio_names;
$this->subtitle_tracks = $subtitle_tracks;
}
public static function fromDatabaseRow($row) {
return new HandBrakeCluster_Job(
$row['id'],
$row['name'],
$row['source'],
$row['destination'],
$row['title'],
$row['format'],
$row['video_codec'],
$row['video_width'],
$row['video_height'],
$row['quantizer'],
$row['deinterlace'],
$row['audio_tracks'],
$row['audio_codecs'],
$row['audio_names'],
$row['subtitle_tracks']
);
}
public static function fromId($id) {
$database = HandBrakeCluster_Main::instance()->database();
return HandBrakeCluster_Job::fromDatabaseRow(
$database->selectOne('SELECT * FROM jobs WHERE id=:id', array(
array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT)
)
)
);
}
public static function all() {
$jobs = array();
$database = HandBrakeCluster_Main::instance()->database();
foreach ($database->selectList('SELECT * FROM jobs') as $row) {
$jobs[] = self::fromDatabaseRow($row);
}
return $jobs;
}
public static function allWithStatus($status) {
$jobs = array();
$database = HandBrakeCluster_Main::instance()->database();
foreach ($database->selectList('SELECT * FROM jobs WHERE id IN (SELECT id FROM job_status_current WHERE status=:status)', array(
array('name' => 'status', 'value' => $status, 'type' => PDO::PARAM_INT)
)) as $row) {
$jobs[] = self::fromDatabaseRow($row);
}
return $jobs;
}
protected function loadStatuses() {
if ($this->statuses == null) {
$this->statuses = HandBrakeCluster_JobStatus::allForJob($this->id);
}
}
public function currentStatus() {
$this->loadStatuses();
return $this->statuses[count($this->statuses) - 1];
}
public function id() {
return $this->id;
}
public function name() {
return $this->name;
}
public function source() {
return $this->source;
}
public function destination() {
return $this->destination;
}
public function title() {
return $this->title;
}
};
?>