FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
dbmigrate_1.4-2.0.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
36 function Migrate_14_20($DryRun)
37 {
38  global $PG_CONN;
39 
40  /* array of agent_name, ars file name for tables to create */
41  $ARSarray = array("pkgagent" => "pkgagent_ars",
42  "copyright" => "copyright_ars",
43  "mimetype" => "mimetype_ars",
44  "unpack" => "ununpack_ars",
45  "ununpack" => "ununpack_ars");
46 
47  foreach($ARSarray as $agent_name => $ARStablename)
48  {
49  /* Create the ars table if it doesn't exist */
50  CreateARStable($ARStablename, $DryRun);
51 
52  /* Get the agent_pk */
53  $agent_pk = GetAgentKey($agent_name, "");
54 
55  /* Select the jobqueue records for this agent */
56  $sql = "select distinct job_upload_fk, jq_type, jq_starttime, jq_endtime from jobqueue
57  join job on jq_job_fk=job_pk where jq_type='$agent_name' and (jq_end_bits=1) order by jq_type";
58  $result = pg_query($PG_CONN, $sql);
59  DBCheckResult($result, $sql, __FILE__, __LINE__);
60 
61  /* Loop through jobqueue records inserting ars table rows */
62  while ($row = pg_fetch_assoc($result))
63  {
64  $upload_fk = $row['job_upload_fk'];
65 
66  /* prevent duplicate insert */
67  $sql = "select ars_pk from $ARStablename where agent_fk=$agent_pk and upload_fk=$upload_fk and ars_success=true";
68  $checkrec = pg_query($PG_CONN, $sql);
69  DBCheckResult($checkrec, $sql, __FILE__, __LINE__);
70  $num_rows = pg_num_rows($checkrec);
71  pg_free_result($checkrec);
72  if ($num_rows > 0) continue;
73 
74  /* add ars rec */
75  $sql = "insert into $ARStablename (agent_fk, upload_fk, ars_success, ars_starttime, ars_endtime)
76  values ($agent_pk, $upload_fk, true, '$row[jq_starttime]', '$row[jq_endtime]')";
77  if ($DryRun)
78  echo "DryRun: $sql\n";
79  else
80  {
81  $insresult = pg_query($PG_CONN, $sql);
82  DBCheckResult($insresult, $sql, __FILE__, __LINE__);
83  pg_free_result($insresult);
84  }
85  }
86  pg_free_result($result);
87  }
88 
89  return 0;
90 } // Migrate_14_20
91 
92 
100 function CreateARStable($ARStablename)
101 {
102  global $PG_CONN;
103 
104  if (DB_TableExists($ARStablename)) return;
105 
106  $sql = "CREATE TABLE $ARStablename () INHERITS (ars_master)";
107  $result = pg_query($PG_CONN, $sql);
108  DBCheckResult($result, $sql, __FILE__, __LINE__);
109 }
110 ?>
Migrate_14_20($DryRun)
Create the new ars tables and populate them from the job/jobqueue data.
CreateARStable($ARStablename)
Create ars table.
DB_TableExists($tableName)
Check if table exists.
Definition: common-db.php:225
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198
GetAgentKey($agentName, $agentDesc)
Get the latest enabled agent_pk for a given agent.