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) {
82 $db_conf_file = $fossology_testconfig .
"/Db.conf";
84 $PG_CONN = pg_connect(str_replace(
";",
" ", file_get_contents($db_conf_file)));
86 if (empty($PG_CONN)) {
87 print
"Error - could not connect to test db via $db_conf_file\n";
90 print
"Successfully connected to test db\n";
102 function check_agent_status($test_dbh, $agent_name, $upload_id) {
104 $ars_table_name = $agent_name.
"_ars";
106 $sql =
"SELECT count(*) FROM $ars_table_name where upload_fk = $upload_id and ars_success=true;";
108 #$result = pg_query($PG_CONN, $sql); 109 $result = pg_query($test_dbh, $sql);
110 $count = pg_num_rows($result);
111 pg_free_result($result);
112 if(1 == $count)
return 1;
119 function add_user($user=
'fossy', $password=
'fossy') {
122 $Seed = rand() . rand();
123 $Hash = sha1($Seed . $password);
124 $sql =
"SELECT * FROM users WHERE user_name = '$user';";
125 $result = pg_query($PG_CONN, $sql);
126 $row0 = pg_fetch_assoc($result);
127 pg_free_result($result);
128 if (empty($row0[
'user_name'])) {
130 $SQL =
"INSERT INTO users (user_name,user_desc,user_seed,user_pass," .
131 "user_perm,user_email,email_notify,root_folder_fk) 132 VALUES ('$user','Default Administrator','$Seed','$Hash',10,'$password','y',1);";
134 $result = pg_query($PG_CONN, $SQL);
135 pg_free_result($result);
142 function preparations() {
146 if (is_dir(
"/srv/fossologyTestRepo/$REPO_NAME")) {
147 exec(
"sudo chmod 2770 /srv/fossologyTestRepo/$REPO_NAME");
148 exec(
"sudo chown fossy /srv/fossologyTestRepo/$REPO_NAME -R");
149 exec(
"sudo chgrp fossy /srv/fossologyTestRepo/$REPO_NAME -R");
151 if (is_dir($SYSCONF_DIR)) {
152 exec(
"sudo chown fossy $SYSCONF_DIR -R");
153 exec(
"sudo chgrp fossy $SYSCONF_DIR -R");
160 function stop_scheduler() {
163 $scheduler_path =
"$SYSCONF_DIR/mods-enabled/scheduler/agent/fo_scheduler";
164 exec(
"sudo $scheduler_path -k");
170 function scheduler_operation() {
172 $scheduler_path =
"/usr/local/share/fossology/scheduler/agent/fo_scheduler";
173 exec(
"sudo $scheduler_path -k");
174 $scheduler_path =
"$SYSCONF_DIR/mods-enabled/scheduler/agent/fo_scheduler";
175 exec(
"sudo $scheduler_path -k");
176 exec(
"sudo $scheduler_path --daemon --reset --verbose=952 -c $SYSCONF_DIR");
182 function add_proxy($proxy_type=
'http_proxy', $porxy=
'web-proxy.cce.hp.com:8088') {
185 $foss_conf = $SYSCONF_DIR.
"/fossology.conf";
186 exec(
"sudo sed 's/.$proxy_type.*=.*/$proxy_type=$porxy/' $foss_conf >/tmp/fossology.conf");
187 exec(
"sudo mv /tmp/fossology.conf $foss_conf");
198 function get_uploadtree_id($test_dbh, $upload_id) {
199 $sql =
"SELECT uploadtree_pk from uploadtree where upload_fk =$upload_id order by uploadtree_pk limit 1;";
200 $result = pg_query($test_dbh, $sql);
201 $row = pg_fetch_assoc($result);
202 $uploadtree_id = $row[
'uploadtree_pk'];
203 pg_free_result($result);
204 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