diff options
author | Preston Cody <codeman@gentoo.org> | 2007-07-22 22:01:41 +0000 |
---|---|---|
committer | Preston Cody <codeman@gentoo.org> | 2007-07-22 22:01:41 +0000 |
commit | cc5175182923efb642096aedd506c624e4ce7108 (patch) | |
tree | 4adade904fbe681329e737ee481ac0fed86f2b78 | |
parent | adding seed data for the jobs and scripts sequences. (diff) | |
download | scire-cc5175182923efb642096aedd506c624e4ce7108.tar.gz scire-cc5175182923efb642096aedd506c624e4ce7108.tar.bz2 scire-cc5175182923efb642096aedd506c624e4ce7108.zip |
in DB.php:
added get_next_id to grab the next id from a sequence
added now to insert the timestamp in whatever DB format.
in functions:
added get_client_statuses() for clients pages
modified add_client and add_job to use $db->now()
fixed add_job to use the sequence. made the code simpler.
fixed clients and clientgroups addition.
heavily modified the script addition. uses sequence
also adds tags passed to it now.
svn path=/; revision=238
-rw-r--r-- | scire/.lib/DB.php | 16 | ||||
-rwxr-xr-x | scire/.lib/DB_functions.php | 102 |
2 files changed, 75 insertions, 43 deletions
diff --git a/scire/.lib/DB.php b/scire/.lib/DB.php index 9fbe611..1cbdd24 100644 --- a/scire/.lib/DB.php +++ b/scire/.lib/DB.php @@ -205,6 +205,22 @@ class DB { } break; + case 'get_next_id': + if (!$args[0]) { + return false; + } + try { + $id = $dbi->GenID($args[0],10); #Generate an ID for the table, start at 10 if not defined yet. + } catch (exception $e) { + print_r($e); + } + return $id; + case 'now': + try { + $time = $dbi->DBDate(time()); + } catch (exception $e) { + print_r($e); + } default: $this->error = 'unknown method'; return false; diff --git a/scire/.lib/DB_functions.php b/scire/.lib/DB_functions.php index b8eca73..66b7079 100755 --- a/scire/.lib/DB_functions.php +++ b/scire/.lib/DB_functions.php @@ -72,9 +72,19 @@ function get_scire_client($clientid) { } } +function get_client_statuses() { + global $db; + $result = $db->select('*', 'client_status'); + if ($result && count($result) > 0) { + return $result; + } else { + return array(); + } +} + function scire_add_client($clientid, $digest, $hostname, $mac, $ip, $profileid, $osid, $contact, $status, $installtime, $assetid) { #clientid, assetid, digest, cert, hostname, mac, ip, gli_profile, osid, status, contact, installtime - if (!$installtime) {$installtime = "NOW()"; } + if (!$installtime) {$installtime = $db->now(); } global $db; #we need to add the client to the axo table first and then to the clients $result = $db->insert('clients', array('clientid' => $clientid, 'digest' => $digest, 'hostname' => $hostname, 'mac' => $mac, 'ip' => $ip, 'gli_profile' => $profileid, 'osid' => $osid, 'contact' => $contact, 'status' => $status, 'installtime' => $installtime, 'assetid' => $assetid)); @@ -335,44 +345,38 @@ function scire_reject_client($clientid) { } function scire_add_job($script, $priority, $creator, $permission, $description, $pending, $clients, $clientgroups, $job_dependency, $run_schedule, $validity_period) { - global $db; - #First make the job - $db->query('LOCK TABLES jobs WRITE'); #LOCK TABLE - $jobid = 0; - $result = $db->insert('jobs', array('script' => $script, 'priority' => $priority, 'created' => "NOW", 'creator' => $creator, 'permission' => $permission, 'description' => $description, 'pending' => $pending )); - if ($result) { - $jobid = $db->query('SELECT LAST_INSERT_ID() as jobid'); -# print_r($jobid); #debugging -# print "******** JOBID IS ".$jobid[0][jobid]." ******* <br>"; #debugging. - $jobid = $jobid[0][jobid]; - } else { - print $result; - $db->query('UNLOCK TABLES'); #UNLOCK - return $db->error; - } - $db->query('UNLOCK TABLES'); #UNLOCK - #Now add the conditions and recurrance - - $result = $db->insert('job_conditions', array('jobid' => $jobid, 'job_dependency' => $job_dependency, 'run_schedule' => $run_schedule, 'validity_period' => $validity_period)); - if (!$result) { - return $db->error; - } - - #Now add the clients. - foreach ($clients as $client) { - $result = $db->query('INSERT INTO `jobs_clients` (jobid, clientid) '. - " VALUES($jobid, $client)"); + global $db; + #First make the job id + $jobid = $db->get_next_id('jobs_seq'); + print "Got a Job ID, it is $jobid <br>"; + $result = $db->insert('jobs', array('jobid' => $jobid, 'script' => $script, 'priority' => $priority, 'created' => $db->now(), 'creator' => $creator, 'permission' => $permission, 'description' => $description, 'pending' => $pending )); if (!$result) { - return $db->error; + return $db->error; } - } - foreach ($clientgroups as $cgroup) { - $result = $db->insert('jobs_clients', array('jobid' => $jobid, 'groupid' => $cgroup)); + $result = $db->insert('job_conditions', array('jobid' => $jobid, 'job_dependency' => $job_dependency, 'run_schedule' => $run_schedule, 'validity_period' => $validity_period)); if (!$result) { - return $db->error; + return $db->error; } - } - return true; + + #Now add the clients. + if ($clients) { + foreach ($clients as $client) { + $result = $db->insert('jobs_clients', array('jobid' => $jobid, 'clientid' => $client)); + if (!$result) { + return $db->error; + } + } + } + + if ($clientgroups) { + foreach ($clientgroups as $cgroup) { + $result = $db->insert('jobs_clients', array('jobid' => $jobid, 'groupid' => $cgroup)); + if (!$result) { + return $db->error; + } + } + } + return 0; #Success } function get_scire_jobs($orderby, $direction, $status='Pending') { @@ -447,14 +451,26 @@ function scire_edit_job($jobid, $fields) { } -function scire_add_script($name, $desc, $location, $script_data, $log_location, $success_code, $run_as, $priority, $permission, $pp_location, $pp_script_data) { - global $db; - $result = $db->insert('scripts', array('name' => $name, 'description' => $desc, 'location' => $location, 'script_data' => $script_data, 'log_location' => $log_location, 'success_code' => $success_code, 'run_as' => $run_as, 'priority' => $priority, 'permission' => $permission, 'pp_location' => $pp_location, 'pp_script_data' => $pp_script_data )); - if ($result) { - return true; - } else { - return $db->error; - } +function scire_add_script($name, $desc, $location, $script_data, $log_location, $success_code, $run_as, $priority, $permission, $pp_location, $pp_script_data, $script_tags) { + global $db; + # First make the script ID + $scriptid = $db->get_next_id('scripts_seq'); + print "Got a Script ID, it is $scriptid<br>"; + + $result = $db->insert('scripts', array('scriptid' => $scriptid, 'name' => $name, 'description' => $desc, 'location' => $location, 'script_data' => $script_data, 'log_location' => $log_location, 'success_code' => $success_code, 'run_as' => $run_as, 'priority' => $priority, 'permission' => $permission, 'pp_location' => $pp_location, 'pp_script_data' => $pp_script_data )); + if (!$result) { + return $db->error; + } + + #Now add the tags. + foreach ($script_tags as $name => $value) { + $result = $db->insert('dyn_tags', array('scriptid' => $scriptid, 'tag' => $name, 'tag_value' => $value) ); + if (!$result) { + return $db->error; + } + } + + return 0; #Success } |