26 function create_db() {
34 exec($DB_COMMAND, $dbout, $rc);
35 preg_match(
"/(\d+)/", $dbout[0], $matches);
36 $test_name = $matches[1];
37 $DB_NAME =
"fosstest".$test_name;
38 $REPO_NAME =
"testDbRepo".$test_name;
39 $SYSCONF_DIR = $dbout[0];
40 $PG_CONN = pg_connect(
"host=localhost port=5432 dbname=$DB_NAME user=fossy password=fossy")
41 or die("Could not connect");
53 exec(
"$DB_COMMAND -d $DB_NAME");
63 function get_upload_id($upload_info) {
65 preg_match(
"/UploadPk is: '(\d+)'/", $upload_info, $matches);
66 $upload_id = $matches[1];
67 if (!$upload_id)
return false;
68 else return $upload_id;
79 function connect_to_DB($fossology_testconfig) {
80 $test_pg_conn = FALSE;
82 $db_conf_file = $fossology_testconfig .
"/Db.conf";
84 $test_pg_conn = pg_connect(str_replace(
";",
" ", file_get_contents($db_conf_file)));
86 if (empty($test_pg_conn)) {
87 print
"Error - could not connect to test db via $db_conf_file\n";
90 print
"Successfully connected to test db\n";
92 return($test_pg_conn);
103 function check_agent_status($test_dbh, $agent_name, $upload_id) {
105 $ars_table_name = $agent_name.
"_ars";
107 $sql =
"SELECT upload_fk FROM $ars_table_name where upload_fk = $upload_id and ars_success=true;";
109 #$result = pg_query($PG_CONN, $sql); 110 $result = pg_query($test_dbh, $sql);
111 $count = pg_num_rows($result);
112 pg_free_result($result);
113 if(1 == $count)
return 1;
125 function check_file_uploadtree($test_dbh, $file_name, $upload_id) {
127 $sql =
"SELECT uploadtree_pk FROM uploadtree where upload_fk = $upload_id and ufile_name = '$file_name';";
129 $result = pg_query($test_dbh, $sql);
130 $count = pg_num_rows($result);
131 pg_free_result($result);
142 function add_user($user=
'fossy', $password=
'fossy') {
145 $Seed = rand() . rand();
146 $Hash = sha1($Seed . $password);
147 $sql =
"SELECT * FROM users WHERE user_name = '$user';";
148 $result = pg_query($PG_CONN, $sql);
149 $row0 = pg_fetch_assoc($result);
150 pg_free_result($result);
151 if (empty($row0[
'user_name'])) {
153 $SQL =
"INSERT INTO users (user_name,user_desc,user_seed,user_pass," .
154 "user_perm,user_email,email_notify,root_folder_fk) 155 VALUES ('$user','Default Administrator','$Seed','$Hash',10,'$password','y',1);";
157 $result = pg_query($PG_CONN, $SQL);
158 pg_free_result($result);
165 function preparations() {
169 if (is_dir(
"/srv/fossologyTestRepo/$REPO_NAME")) {
170 exec(
"sudo chmod 2770 /srv/fossologyTestRepo/$REPO_NAME");
171 exec(
"sudo chown fossy /srv/fossologyTestRepo/$REPO_NAME -R");
172 exec(
"sudo chgrp fossy /srv/fossologyTestRepo/$REPO_NAME -R");
174 if (is_dir($SYSCONF_DIR)) {
175 exec(
"sudo chown fossy $SYSCONF_DIR -R");
176 exec(
"sudo chgrp fossy $SYSCONF_DIR -R");
183 function stop_scheduler() {
186 $scheduler_path =
"$SYSCONF_DIR/mods-enabled/scheduler/agent/fo_scheduler";
187 exec(
"sudo $scheduler_path -k");
193 function scheduler_operation() {
195 $scheduler_path =
"/usr/local/share/fossology/scheduler/agent/fo_scheduler";
196 exec(
"sudo $scheduler_path -k");
197 $scheduler_path =
"$SYSCONF_DIR/mods-enabled/scheduler/agent/fo_scheduler";
198 exec(
"sudo $scheduler_path -k");
199 exec(
"sudo $scheduler_path --daemon --reset --verbose=952 -c $SYSCONF_DIR");
205 function add_proxy($proxy_type=
'http_proxy', $porxy=
'web-proxy.cce.hp.com:8088') {
208 $foss_conf = $SYSCONF_DIR.
"/fossology.conf";
209 exec(
"sudo sed 's/.$proxy_type.*=.*/$proxy_type=$porxy/' $foss_conf >/tmp/fossology.conf");
210 exec(
"sudo mv /tmp/fossology.conf $foss_conf");
221 function get_uploadtree_id($test_dbh, $upload_id) {
222 $sql =
"SELECT uploadtree_pk from uploadtree where upload_fk =$upload_id order by uploadtree_pk limit 1;";
223 $result = pg_query($test_dbh, $sql);
224 $row = pg_fetch_assoc($result);
225 $uploadtree_id = $row[
'uploadtree_pk'];
226 pg_free_result($result);
227 return $uploadtree_id;
add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN