FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
admin-bucket-pool.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2010-2013 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 
24 define("TITLE_admin_bucket_pool", _("Duplicate Bucketpool"));
25 
31 {
32  function __construct()
33  {
34  $this->Name = "admin_bucket_pool";
35  $this->Title = TITLE_admin_bucket_pool;
36  $this->MenuList = "Admin::Buckets::Duplicate Bucketpool";
37  $this->DBaccess = PLUGIN_DB_ADMIN;
38  parent::__construct();
39  }
40 
52  function CloneBucketpool($bucketpool_pk, $UpdateDefault, &$msg)
53  {
54  global $PG_CONN;
55 
56  /* select the old bucketpool record */
57  $sql = "select * from bucketpool where bucketpool_pk='$bucketpool_pk' ";
58  $result = pg_query($PG_CONN, $sql);
59  DBCheckResult($result, $sql, __FILE__, __LINE__);
60  $row = pg_fetch_assoc($result);
61  pg_free_result($result);
62 
63  /*
64  * Get the last version for this bucketpool name.
65  * There could be a race condition between getting the last version and
66  * inserting the new version, but this is an admin only function and it
67  * would be pretty odd if two admins were modifying the same bucketpool
68  * at the same instant. Besides if this does occur, the loser will just
69  * get a message about the dup record and no harm done.
70  */
71  $sql = "select max(version) as version from bucketpool where bucketpool_name='$row[bucketpool_name]'";
72  $result = pg_query($PG_CONN, $sql);
73  DBCheckResult($result, $sql, __FILE__, __LINE__);
74  $vrow = pg_fetch_assoc($result);
75  pg_free_result($result);
76  $newversion = $vrow['version'] + 1;
77 
78  /* Insert the new bucketpool record */
79  $sql = "insert into bucketpool (bucketpool_name, version, active, description) select bucketpool_name, '$newversion', active, description from bucketpool where bucketpool_pk=$bucketpool_pk";
80  $result = pg_query($PG_CONN, $sql);
81  DBCheckResult($result, $sql, __FILE__, __LINE__);
82  pg_free_result($result);
83 
84  /* Retrieve the new bucketpool_pk */
85  $sql = "select bucketpool_pk from bucketpool where bucketpool_name='$row[bucketpool_name]' and version='$newversion'";
86  $result = pg_query($PG_CONN, $sql);
87  DBCheckResult($result, $sql, __FILE__, __LINE__);
88  $row = pg_fetch_assoc($result);
89  pg_free_result($result);
90  $newbucketpool_pk = $row['bucketpool_pk'];
91 
92  /* duplicate all the bucketdef records for the new bucketpool_pk */
93  $sql = "insert into bucket_def (bucket_name, bucket_color, bucket_reportorder, bucket_evalorder, bucketpool_fk, bucket_type, bucket_regex, bucket_filename, stopon, applies_to)
94 select bucket_name, bucket_color, bucket_reportorder, bucket_evalorder, $newbucketpool_pk, bucket_type, bucket_regex, bucket_filename, stopon, applies_to from bucket_def where bucketpool_fk=$bucketpool_pk";
95  $insertresult = pg_query($PG_CONN, $sql);
96  DBCheckResult($insertresult, $sql, __FILE__, __LINE__);
97  pg_free_result($insertresult);
98 
99  /* Update default bucket pool in user table for this user only */
100  if ($UpdateDefault == 'on')
101  {
102  $sql = "update users set default_bucketpool_fk='$newbucketpool_pk' where user_pk='$_SESSION[UserId]'";
103  $result = pg_query($PG_CONN, $sql);
104  DBCheckResult($result, $sql, __FILE__, __LINE__);
105  pg_free_result($result);
106  }
107 
108  return $newbucketpool_pk;
109  }
110 
125  public function Output()
126  {
127  global $PROJECTSTATEDIR;
128 
129  /* get the bucketpool_pk to clone */
130  $bucketpool_pk = GetParm("default_bucketpool_fk",PARM_INTEGER);
131  $UpdateDefault = GetParm("updatedefault",PARM_RAW);
132 
133  if (!empty($bucketpool_pk))
134  {
135  $msg = "";
136  $newbucketpool_pk = $this->CloneBucketpool($bucketpool_pk, $UpdateDefault, $msg);
137  $text = _("Your new bucketpool_pk is");
138  $this->vars['message'] = "$text $newbucketpool_pk";
139  }
140 
141  $V = "<p>";
142  $V .= _("The purpose of this is to facilitate editing an existing bucketpool. Make sure you understand");
143  $V .= " <a href='http://www.fossology.org/projects/fossology/wiki/Buckets'>";
144  $V .= _("Creating Bucket Pools");
145  $V .= "</a> ";
146  $V .= _("before continuing.");
147  $V .= _(" It will explain why you should create a new bucketpool rather than edit an old one that has already recorded results.");
148  $V .= "<p>";
149  $V .= _("Steps to modify a bucketpool:");
150  $V .= "<ol>";
151  $V .= "<li>";
152  $V .= _("Create a baseline with your current bucketpool. In other words, run a bucket scan on something. If you do this before creating a new modified bucketpool, you can compare the old results with the new to verify it is working as you expect.");
153  $V .= "<li>";
154  $V .= _("Duplicate the bucketpool (this will increment the bucketpool version and its bucketdef records). You should also check 'Update my default bucketpool' since new bucket jobs only use your default bucketpool.");
155  $V .= "<li>";
156  $V .= _("Duplicate any bucket scripts that you defined in $PROJECTSTATEDIR.");
157  $V .= "<li>";
158  $V .= _("Manually edit the new bucketpool record, if desired.");
159  $V .= "<li>";
160  $V .= _("Manually insert/update/delete the new bucketdef records.");
161  $V .= "<li>";
162  $V .= _("Manually insert a new buckets record in the agent table.");
163  $V .= "<li>";
164  $V .= _("Queue up the new bucket job in Jobs > Schedule Agents.");
165  $V .= "<li>";
166  $V .= _("Use Buckets > Compare to compare the new and old runs. Verify the results.");
167  $V .= "<li>";
168  $V .= _("If you still need to edit the buckets, use Buckets > Remove Bucket Results to remove the previous runs results and repeat starting with editing the bucketpool or def records.");
169  $V .= "<li>";
170  $V .= _("When the bucket results are what you want, then you can reset all the users of the old bucketpool to the new one (manual sql step).");
171  $V .= "</ol>";
172  $V .= "<hr>";
173 
174  $V .= "<form method='POST'>";
175  $text = _("Choose the bucketpool to duplicate");
176  $V .= "$text ";
177  $Val = "";
178  $V .= SelectBucketPool($Val);
179 
180  $V .= "<p>";
181  $text = _("Update my default bucketpool");
182  $V .= "<input type='checkbox' name='updatedefault' checked> $text.";
183  $V .= "<p>";
184  $text = _("Submit");
185  $V .= "<input type='submit' value='$text'>";
186  $V .= "</form>";
187  return $V;
188  }
189 }
190 
191 $NewPlugin = new admin_bucket_pool;
192 $NewPlugin->Initialize();
SelectBucketPool($selected, $active='Y')
Return a select list containing all the active bucketpool&#39;s.
const PARM_RAW
Definition: common-parm.php:33
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:51
Output()
User chooses a bucketpool to duplicate from a select list.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
const PARM_INTEGER
Definition: common-parm.php:25
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
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
CloneBucketpool($bucketpool_pk, $UpdateDefault, &$msg)
Clone a bucketpool and its bucketdef records. Increment the bucketpool version.