コード例 #1
0
 /**
  * @brief Update upload properties (name and description)
  *
  * @param $uploadId upload.upload_pk of record to update
  * @param $newName New upload.upload_filename, and uploadtree.ufle_name
  *        If null, old value is not changed.
  * @param $newDesc New upload description (upload.upload_desc)
  *        If null, old value is not changed.
  *
  * @return 1 if the upload record is updated, 0 if not, 2 if no inputs
  **/
 function UpdateUploadProperties($uploadId, $newName, $newDesc)
 {
     if (empty($newName) and empty($newDesc)) {
         return 2;
     }
     if (!empty($newName)) {
         /* Use pfile_fk to select the correct entry in the upload tree, artifacts
          * (e.g. directories of the upload do not have pfiles).
          */
         $row = $this->dbManager->getSingleRow("SELECT pfile_fk FROM upload WHERE upload_pk=\$1", array($uploadId), __METHOD__ . '.getPfileId');
         if (empty($row)) {
             return 0;
         }
         $pfileFk = $row['pfile_fk'];
         $trimNewName = trim($newName);
         /* Always keep uploadtree.ufile_name and upload.upload_filename in sync */
         $this->dbManager->getSingleRow("UPDATE uploadtree SET ufile_name=\$3 WHERE upload_fk=\$1 AND pfile_fk=\$2", array($uploadId, $pfileFk, $trimNewName), __METHOD__ . '.updateItem');
         $this->dbManager->getSingleRow("UPDATE upload SET upload_filename=\$3 WHERE upload_pk=\$1 AND pfile_fk=\$2", array($uploadId, $pfileFk, $trimNewName), __METHOD__ . '.updateUpload.name');
     }
     if (!empty($newDesc)) {
         $trimNewDesc = trim($newDesc);
         $this->dbManager->getSingleRow("UPDATE upload SET upload_desc=\$2 WHERE upload_pk=\$1", array($uploadId, $trimNewDesc), __METHOD__ . '.updateUpload.desc');
     }
     return 1;
 }
コード例 #2
0
 /**
  * \brief Generate the text for this plugin.
  */
 public function Output()
 {
     /* If this is a POST, then process the request. */
     $folder = GetParm('folder', PARM_INTEGER);
     if (!empty($folder)) {
         $userId = Auth::getUserId();
         $sql = "SELECT folder_name FROM folder join users on (users.user_pk = folder.user_fk or users.user_perm = 10) where folder_pk = \$1 and users.user_pk = \$2;";
         $Folder = $this->dbManager->getSingleRow($sql, array($folder, $userId), __METHOD__ . "GetRowWithFolderName");
         if (!empty($Folder['folder_name'])) {
             $rc = $this->Delete($folder, $userId);
             if (empty($rc)) {
                 /* Need to refresh the screen */
                 $text = _("Deletion of folder ");
                 $text1 = _(" added to job queue");
                 $this->vars['message'] = $text . $Folder['folder_name'] . $text1;
             } else {
                 $text = _("Deletion of ");
                 $text1 = _(" failed: ");
                 $this->vars['message'] = $text . $Folder['folder_name'] . $text1 . $rc;
             }
         } else {
             $text = _("Cannot delete this folder :: Permission denied");
             $this->vars['message'] = $text;
         }
     }
     $V = "<form method='post'>\n";
     // no url = this url
     $text = _("Select the folder to");
     $text1 = _("delete");
     $V .= "{$text} <em>{$text1}</em>.\n";
     $V .= "<ul>\n";
     $text = _("This will");
     $text1 = _("delete");
     $text2 = _("the folder, all subfolders, and all uploaded files stored within the folder!");
     $V .= "<li>{$text} <em>{$text1}</em> {$text2}\n";
     $text = _("Be very careful with your selection since you can delete a lot of work!");
     $V .= "<li>{$text}\n";
     $text = _("All analysis only associated with the deleted uploads will also be deleted.");
     $V .= "<li>{$text}\n";
     $text = _("THERE IS NO UNDELETE. When you select something to delete, it will be removed from the database and file repository.");
     $V .= "<li>{$text}\n";
     $V .= "</ul>\n";
     $text = _("Select the folder to delete:  ");
     $V .= "<P>{$text}\n";
     $V .= "<select name='folder'>\n";
     $text = _("select folder");
     $V .= "<option value=''>[{$text}]</option>\n";
     $V .= FolderListOption(-1, 0);
     $V .= "</select><P />\n";
     $text = _("Delete");
     $V .= "<input type='submit' value='{$text}'>\n";
     $V .= "</form>\n";
     return $V;
 }
コード例 #3
0
 /**
  * @brief : returns 1 when jobs are running else 0
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $response = '1';
     $jobInfo = $this->dbManager->getSingleRow("SELECT jq_end_bits FROM jobqueue WHERE jq_end_bits ='0' LIMIT 1");
     if (empty($jobInfo)) {
         $response = '0';
     }
     $status = 1;
     ReportCachePurgeAll();
     $status = empty($status) ? Response::HTTP_INTERNAL_SERVER_ERROR : Response::HTTP_OK;
     return new Response(json_encode(array("status" => $response)), $status, array('content-type' => 'text/json'));
 }
コード例 #4
0
ファイル: TreeDao.php プロジェクト: DanielDobre/fossology
 public function getRepoPathOfPfile($pfileId, $repo = "files")
 {
     $pfileRow = $this->dbManager->getSingleRow('SELECT * FROM pfile WHERE pfile_pk=$1', array($pfileId));
     global $LIBEXECDIR;
     if (empty($pfileRow['pfile_sha1'])) {
         return null;
     }
     $hash = $pfileRow['pfile_sha1'] . "." . $pfileRow['pfile_md5'] . "." . $pfileRow['pfile_size'];
     $path = '';
     exec("{$LIBEXECDIR}/reppath {$repo} {$hash}", $path);
     return $path[0];
 }
コード例 #5
0
 /**
  * \brief Generate the text for this plugin.
  */
 public function Output()
 {
     /* If this is a POST, then process the request. */
     $FolderSelectId = GetParm('selectfolderid', PARM_INTEGER);
     if (empty($FolderSelectId)) {
         $FolderSelectId = FolderGetTop();
     }
     $FolderId = GetParm('oldfolderid', PARM_INTEGER);
     $NewName = GetParm('newname', PARM_TEXT);
     $NewDesc = GetParm('newdesc', PARM_TEXT);
     if (!empty($FolderId)) {
         $FolderSelectId = $FolderId;
         $rc = $this->Edit($FolderId, $NewName, $NewDesc);
         if ($rc == 1) {
             /* Need to refresh the screen */
             $text = _("Folder Properties changed");
             $this->vars["message"] = $text;
         }
     }
     /* Get the folder info */
     $sql = 'SELECT * FROM folder WHERE folder_pk = $1;';
     $Folder = $this->dbManager->getSingleRow($sql, array($FolderSelectId), __METHOD__ . "getFolderRow");
     /* Display the form */
     $formVars["onchangeURI"] = Traceback_uri() . "?mod=" . $this->Name . "&selectfolderid=";
     $formVars["folderListOption"] = FolderListOption(-1, 0, 1, $FolderSelectId);
     $formVars["folder_name"] = $Folder['folder_name'];
     $formVars["folder_desc"] = $Folder['folder_desc'];
     return $this->renderString("admin-folder-edit-form.html.twig", $formVars);
 }
コード例 #6
0
ファイル: LicenseDaoTest.php プロジェクト: rlintu/fossology
 public function testGetAgentFileLicenseMatchesWithLicenseMapping()
 {
     $this->testDb->createPlainTables(array('license_ref', 'uploadtree', 'license_file', 'agent', 'license_map'));
     $this->testDb->insertData_license_ref();
     $lic0 = $this->dbManager->getSingleRow("Select * from license_ref limit 1", array(), __METHOD__ . '.anyLicense');
     $licRefId = $lic0['rf_pk'];
     $licenseFileId = 1;
     $pfileId = 42;
     $agentId = 23;
     $matchPercent = 50;
     $uploadtreeId = 512;
     $uploadID = 123;
     $left = 2009;
     $right = 2014;
     $agentName = "fake";
     $agentRev = 1;
     $lic1 = $this->dbManager->getSingleRow("SELECT * FROM license_ref WHERE rf_pk!=\$1 LIMIT 1", array($licRefId), __METHOD__ . '.anyOtherLicense');
     $licVarId = $lic1['rf_pk'];
     $mydate = "'2014-06-04 14:01:30.551093+02'";
     $this->dbManager->insertTableRow('license_map', array('license_map_pk' => 0, 'rf_fk' => $licVarId, 'rf_parent' => $licRefId, 'usage' => LicenseMap::CONCLUSION));
     $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk, rf_fk, agent_fk, rf_match_pct, rf_timestamp, pfile_fk)\n            VALUES ({$licenseFileId}, {$licVarId}, {$agentId}, {$matchPercent}, {$mydate}, {$pfileId})");
     $this->dbManager->queryOnce("INSERT INTO uploadtree (uploadtree_pk, upload_fk, pfile_fk, lft, rgt)\n            VALUES ({$uploadtreeId}, {$uploadID}, {$pfileId}, {$left}, {$right})");
     $stmt = __METHOD__ . '.insert.agent';
     $this->dbManager->prepare($stmt, "INSERT INTO agent (agent_pk, agent_name, agent_rev, agent_enabled) VALUES (\$1,\$2,\$3,\$4)");
     $this->dbManager->execute($stmt, array($agentId, $agentName, $agentRev, 'true'));
     $licDao = new LicenseDao($this->dbManager);
     $itemTreeBounds = new ItemTreeBounds($uploadtreeId, "uploadtree", $uploadID, $left, $right);
     $matches = $licDao->getAgentFileLicenseMatches($itemTreeBounds, LicenseMap::CONCLUSION);
     $licenseRef = new LicenseRef($licRefId, $lic0['rf_shortname'], $lic0['rf_fullname']);
     $agentRef = new AgentRef($agentId, $agentName, $agentRev);
     $expected = array(new LicenseMatch($pfileId, $licenseRef, $agentRef, $licenseFileId, $matchPercent));
     assertThat($matches, equalTo($expected));
     $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
 }
コード例 #7
0
ファイル: admin-dashboard.php プロジェクト: rlintu/fossology
 /**
  * \brief Database metrics
  * \returns html table containing metrics
  */
 function DatabaseMetrics()
 {
     $V = "<table border=1>\n";
     $text = _("Metric");
     $text1 = _("Total");
     $V .= "<tr><th>{$text}</th><th>{$text1}</th></tr>\n";
     /* Database size */
     $sql = "SELECT pg_database_size('fossology') as val;";
     $row = $this->dbManager->getSingleRow($sql, array(), __METHOD__ . "get_Size");
     $Size = HumanSize($row['val']);
     $text = _("FOSSology database size");
     $V .= "<tr><td>{$text}</td>";
     $V .= "<td align='right'> {$Size} </td></tr>\n";
     /**** Version ****/
     $text = _("Postgresql version");
     $V .= "<tr><td>{$text}</td>";
     $V .= "<td align='right'> {$this->pgVersion[server]} </td></tr>\n";
     /**** Query stats ****/
     // count current queries
     $sql = "SELECT count(*) AS val FROM pg_stat_activity";
     $row = $this->dbManager->getSingleRow($sql, array(), __METHOD__ . "get_connection_count");
     $connection_count = $row['val'];
     /**** Active connection count ****/
     $current_query = strcmp($this->pgVersion['server'], "9.2") >= 0 ? "state" : "current_query";
     $text = _("Active database connections");
     $V .= "<tr><td>{$text}</td>";
     $V .= "<td align='right'>" . number_format($connection_count, 0, "", ",") . "</td></tr>\n";
     $V .= "</table>\n";
     return $V;
 }
コード例 #8
0
 /**
  * @param int $uploadId
  * @return int
  * @throws \Exception
  */
 public function getStatus($uploadId)
 {
     $row = $this->dbManager->getSingleRow("SELECT status_fk FROM upload_clearing WHERE upload_fk=\$1 AND group_fk=\$2", array($uploadId, $this->groupId));
     if (false === $row) {
         throw new \Exception("cannot find uploadId={$uploadId}");
     }
     return $row['status_fk'];
 }
コード例 #9
0
 private function getJobQueueId($uploadTreeId)
 {
     $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId);
     $uploadId = intval($uploadEntry['upload_fk']);
     if ($uploadId <= 0) {
         throw new Exception('permission denied');
     }
     $bulkScope = filter_input(INPUT_POST, 'bulkScope');
     switch ($bulkScope) {
         case 'u':
             $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
             $row = $this->dbManager->getSingleRow("SELECT uploadtree_pk FROM {$uploadTreeTable} WHERE upload_fk = \$1 ORDER BY uploadtree_pk LIMIT 1", array($uploadId), __METHOD__ . "adam" . $uploadTreeTable);
             $uploadTreeId = $row['uploadtree_pk'];
             break;
         case 'f':
             if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) {
                 $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId;
             }
             break;
         default:
             throw new InvalidArgumentException('bad scope request');
     }
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     $refText = filter_input(INPUT_POST, 'refText');
     $action = filter_input(INPUT_POST, 'bulkAction');
     $licenseId = GetParm('licenseId', PARM_INTEGER);
     $removing = $action === 'remove';
     $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseId, $removing, $refText);
     if ($bulkId <= 0) {
         throw new Exception('cannot insert bulk reference');
     }
     $upload = $this->uploadDao->getUpload($uploadId);
     $uploadName = $upload->getFilename();
     $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId);
     /** @var DeciderJobAgentPlugin $deciderPlugin */
     $deciderPlugin = plugin_find("agent_deciderjob");
     $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId));
     $conflictStrategyId = intval(filter_input(INPUT_POST, 'forceDecision'));
     $errorMsg = '';
     $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId);
     if (!empty($errorMsg)) {
         throw new Exception(str_replace('<br>', "\n", $errorMsg));
     }
     return $jqId;
 }
コード例 #10
0
ファイル: UserDaoTest.php プロジェクト: DanielDobre/fossology
 public function testAddGroup()
 {
     $this->dbManager->queryOnce('CREATE TABLE groups (group_pk integer NOT NULL PRIMARY KEY, group_name varchar(64))');
     $this->testDb->insertData(array('groups'));
     $groupId = $this->userDao->addGroup($groupName = 'newGroup');
     $row = $this->dbManager->getSingleRow('SELECT group_name FROM groups WHERE group_pk=$1', array($groupId));
     assertThat($row['group_name'], equalTo($groupName));
 }
コード例 #11
0
ファイル: FolderDao.php プロジェクト: rlintu/fossology
 /**
  * @param int $folderId
  * @return Folder|null
  */
 public function getFolder($folderId)
 {
     $folderRow = $this->dbManager->getSingleRow('SELECT * FROM folder WHERE folder_pk = $1', array($folderId));
     if (!$folderRow) {
         return null;
     }
     return new Folder($folderRow['folder_pk'], $folderRow['folder_name'], $folderRow['folder_desc'], $folderRow['folder_perm']);
 }
コード例 #12
0
 private function getKeyFromShortname($shortname)
 {
     if (array_key_exists($shortname, $this->nkMap)) {
         return $this->nkMap[$shortname];
     }
     $row = $this->dbManager->getSingleRow('SELECT rf_pk FROM license_ref WHERE rf_shortname=$1', array($shortname));
     $this->nkMap[$shortname] = $row === false ? false : $row['rf_pk'];
     return $this->nkMap[$shortname];
 }
コード例 #13
0
ファイル: admin-config.php プロジェクト: rlintu/fossology
 /**
  * \brief Generate output.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $newarray = GetParm("new", PARM_RAW);
     $oldarray = GetParm("old", PARM_RAW);
     /* Compare new and old array
      * and update DB with new values */
     $UpdateMsg = "";
     if (!empty($newarray)) {
         foreach ($newarray as $VarName => $VarValue) {
             if ($VarValue != $oldarray[$VarName]) {
                 /* get validation_function row from sysconfig table */
                 $sys_array = $this->dbManager->getSingleRow("select validation_function, ui_label from sysconfig where variablename=\$1", array($VarName), __METHOD__ . '.getVarNameData');
                 $validation_function = $sys_array['validation_function'];
                 $ui_label = $sys_array['ui_label'];
                 $is_empty = empty($validation_function);
                 /* 1. the validation_function is empty
                     2. the validation_function is not empty, and after checking, the value is valid
                    update sysconfig table
                    */
                 if ($is_empty || !$is_empty && 1 == $validation_function($VarValue)) {
                     $this->dbManager->getSingleRow("update sysconfig set conf_value=\$1 where variablename=\$2", array($VarValue, $VarName), __METHOD__ . '.setVarNameData');
                     if (!empty($UpdateMsg)) {
                         $UpdateMsg .= ", ";
                     }
                     $UpdateMsg .= $VarName;
                 } else {
                     if (!$is_empty && 0 == $validation_function($VarValue)) {
                         if (!strcmp($validation_function, 'check_boolean')) {
                             $warning_msg = _("Error: You set {$ui_label} to {$VarValue}. Valid  values are 'true' and 'false'.");
                             echo "<script>alert('{$warning_msg}');</script>";
                         } else {
                             if (strpos($validation_function, "url")) {
                                 $warning_msg = _("Error: {$ui_label} {$VarValue}, is not a reachable URL.");
                                 echo "<script>alert('{$warning_msg}');</script>";
                             }
                         }
                     }
                 }
             }
         }
         if (!empty($UpdateMsg)) {
             $UpdateMsg .= _(" updated.");
         }
     }
     $OutBuf = '';
     if ($this->OutputType == 'HTML') {
         if ($UpdateMsg) {
             $OutBuf .= "<span style='background-color:#ff8a8a'>{$UpdateMsg}</style><hr>";
         }
         $OutBuf .= $this->HTMLout();
     }
     $this->vars['content'] = $OutBuf;
 }
コード例 #14
0
ファイル: AjaxJobInfo.php プロジェクト: DanielDobre/fossology
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $userId = $_SESSION['UserId'];
     $jqIds = (array) $request->get('jqIds');
     $result = array();
     foreach ($jqIds as $jq_pk) {
         $jobInfo = $this->dbManager->getSingleRow("SELECT jobqueue.jq_end_bits as end_bits FROM jobqueue INNER JOIN job ON jobqueue.jq_job_fk = job.job_pk\n          WHERE jobqueue.jq_pk = \$1 AND job_user_fk = \$2", array($jq_pk, $userId));
         if ($jobInfo !== false) {
             $result[$jq_pk] = array('end_bits' => $jobInfo['end_bits']);
         }
     }
     ReportCachePurgeAll();
     $status = empty($result) ? Response::HTTP_INTERNAL_SERVER_ERROR : Response::HTTP_OK;
     if (empty($result)) {
         $result = array("error" => "no info");
     }
     $response = new Response(json_encode($result), $status, array('content-type' => 'text/json'));
     return $response;
 }
コード例 #15
0
 public function getDecision($tableName, $pfileId)
 {
     $statementName = __METHOD__ . $tableName;
     $sql = "SELECT * FROM {$tableName} where pfile_fk = \$1 order by copyright_decision_pk desc limit 1";
     $res = $this->dbManager->getSingleRow($sql, array($pfileId), $statementName);
     $description = $res['description'];
     $textFinding = $res['textfinding'];
     $comment = $res['comment'];
     $decisionType = $res['clearing_decision_type_fk'];
     return array($description, $textFinding, $comment, $decisionType);
 }
コード例 #16
0
 public function testCopyContent()
 {
     $this->folderDao->ensureTopLevelFolder();
     $folderA = $this->folderDao->insertFolder($folderName = 'A', '/A', FolderDao::TOP_LEVEL);
     $folderB = $this->folderDao->insertFolder($folderName = 'B', '/A/B', $folderA);
     $this->folderDao->insertFolder($folderName = 'C', '/C', FolderDao::TOP_LEVEL);
     $fc = $this->dbManager->getSingleRow('SELECT foldercontents_pk FROM foldercontents WHERE child_id=$1', array($folderB), __METHOD__ . '.needs.the.foldercontent_pk');
     $this->folderDao->copyContent($fc['foldercontents_pk'], FolderDao::TOP_LEVEL);
     assertThat($this->folderDao->getFolderChildFolders($folderA), is(arrayWithSize(1)));
     assertThat($this->folderDao->getFolderChildFolders(FolderDao::TOP_LEVEL), is(arrayWithSize(3)));
 }
コード例 #17
0
ファイル: ClearingDaoTest.php プロジェクト: rlintu/fossology
 public function testupdateClearingEvent()
 {
     $this->testDb->createSequences(array('clearing_event_clearing_event_pk_seq'));
     $this->testDb->createConstraints(array('clearing_event_pkey'));
     $this->dbManager->queryOnce("ALTER TABLE clearing_event ALTER COLUMN clearing_event_pk SET DEFAULT nextval('clearing_event_clearing_event_pk_seq'::regclass)");
     $this->clearingDao->updateClearingEvent($uploadTreeId = 301, $userId = 1, $groupId = 1, $licenseId = 402, $what = 'comment', $changeCom = 'abc123');
     $rowPast = $this->dbManager->getSingleRow('SELECT * FROM clearing_event WHERE uploadtree_fk=$1 AND rf_fk=$2 ORDER BY clearing_event_pk DESC LIMIT 1', array($uploadTreeId, $licenseId), __METHOD__ . 'beforeReportinfo');
     assertThat($rowPast['comment'], equalTo($changeCom));
     $this->clearingDao->updateClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $what = 'reportinfo', $changeRep = 'def456');
     $rowFuture = $this->dbManager->getSingleRow('SELECT * FROM clearing_event WHERE uploadtree_fk=$1 AND rf_fk=$2 ORDER BY clearing_event_pk DESC LIMIT 1', array($uploadTreeId, $licenseId), __METHOD__ . 'afterReportinfo');
     assertThat($rowFuture['comment'], equalTo($changeCom));
     assertThat($rowFuture['reportinfo'], equalTo($changeRep));
 }
コード例 #18
0
 protected function getCopyrights($upload_pk, $item, $uploadTreeTableName, $agentId, $type, $filter)
 {
     $offset = GetParm('iDisplayStart', PARM_INTEGER);
     $limit = GetParm('iDisplayLength', PARM_INTEGER);
     $tableName = $this->getTableName($type);
     $orderString = $this->getOrderString();
     list($left, $right) = $this->uploadDao->getLeftAndRight($item, $uploadTreeTableName);
     if ($filter == "") {
         $filter = "none";
     }
     $sql_upload = "";
     if ('uploadtree_a' == $uploadTreeTableName) {
         $sql_upload = " AND UT.upload_fk={$upload_pk} ";
     }
     $join = "";
     $filterQuery = "";
     if ($type == 'statement' && $filter == "nolic") {
         $noLicStr = "No_license_found";
         $voidLicStr = "Void";
         $join = " INNER JOIN license_file AS LF on cp.pfile_fk=LF.pfile_fk ";
         $filterQuery = " AND LF.rf_fk IN (SELECT rf_pk FROM license_ref WHERE rf_shortname IN ('{$noLicStr}','{$voidLicStr}')) ";
     } else {
         // No filter, nothing to do
     }
     $params = array($left, $right, $type, $agentId);
     $filterParms = $params;
     $searchFilter = $this->addSearchFilter($filterParms);
     $unorderedQuery = "FROM {$tableName} AS cp " . "INNER JOIN {$uploadTreeTableName} AS UT ON cp.pfile_fk = UT.pfile_fk " . $join . "WHERE cp.content!='' " . "AND ( UT.lft  BETWEEN  \$1 AND  \$2 ) " . "AND cp.type = \$3 " . "AND cp.agent_fk= \$4 " . $sql_upload;
     $totalFilter = $filterQuery . " " . $searchFilter;
     $grouping = " GROUP BY content ";
     $countQuery = "SELECT count(*) FROM (SELECT content, count(*) {$unorderedQuery} {$totalFilter} {$grouping}) as K";
     $iTotalDisplayRecordsRow = $this->dbManager->getSingleRow($countQuery, $filterParms, __METHOD__ . $tableName . ".count");
     $iTotalDisplayRecords = $iTotalDisplayRecordsRow['count'];
     $countAllQuery = "SELECT count(*) FROM (SELECT content, count(*) {$unorderedQuery}{$grouping}) as K";
     $iTotalRecordsRow = $this->dbManager->getSingleRow($countAllQuery, $params, __METHOD__, $tableName . "count.all");
     $iTotalRecords = $iTotalRecordsRow['count'];
     $range = "";
     $filterParms[] = $offset;
     $range .= ' OFFSET $' . count($filterParms);
     $filterParms[] = $limit;
     $range .= ' LIMIT $' . count($filterParms);
     $sql = "SELECT content, hash, count(*) as copyright_count  " . $unorderedQuery . $totalFilter . " GROUP BY content, hash " . $orderString . $range;
     $statement = __METHOD__ . $filter . $tableName . $uploadTreeTableName;
     $this->dbManager->prepare($statement, $sql);
     $result = $this->dbManager->execute($statement, $filterParms);
     $rows = $this->dbManager->fetchAll($result);
     $this->dbManager->freeResult($result);
     return array($rows, $iTotalDisplayRecords, $iTotalRecords);
 }
コード例 #19
0
ファイル: spdx2.php プロジェクト: rlintu/fossology
 /**
  * @param UploadTree $upload
  * @return string
  */
 protected function getVerificationCode(Upload $upload)
 {
     $stmt = __METHOD__;
     $param = array();
     if ($upload->getTreeTableName() == 'uploadtree_a') {
         $sql = $upload->getTreeTableName() . ' WHERE upload_fk=$1 AND';
         $param[] = $upload->getId();
     } else {
         $sql = $upload->getTreeTableName() . ' WHERE';
         $stmt .= '.' . $upload->getTreeTableName();
     }
     $sql = "SELECT STRING_AGG(lower_sha1,'') concat_sha1 FROM\n       (SELECT LOWER(pfile_sha1) lower_sha1 FROM pfile, {$sql} pfile_fk=pfile_pk ORDER BY pfile_sha1) templist";
     $filelistPack = $this->dbManager->getSingleRow($sql, $param, $stmt);
     return sha1($filelistPack['concat_sha1']);
 }
コード例 #20
0
 public function testUpdateTable()
 {
     $this->setUpClearingTables();
     $item = new ItemTreeBounds(6, 'uploadtree_a', 1, 17, 18);
     $hash2 = '0x3a910990f114f12f';
     $ctPk = 2;
     $uploadDao = M::mock('Fossology\\Lib\\Dao\\UploadDao');
     $copyrightDao = new CopyrightDao($this->dbManager, $uploadDao);
     $copyrightDao->updateTable($item, $hash2, $content = 'foo', $userId = 55);
     $audit = $this->dbManager->getSingleRow('SELECT * FROM copyright_audit WHERE ct_fk=$1', array($ctPk), __METHOD__ . '.audit');
     assertThat($audit, hasKeyValuePair('ct_fk', $ctPk));
     assertThat($audit, hasKeyValuePair('oldtext', 'modified versions of this software. you must, however, include this copyright statement along with any code built using doc software that you release. no copyright statement needs to be provided if you'));
     assertThat($audit, hasKeyValuePair('user_fk', $userId));
     $updatedCp = $this->dbManager->getSingleRow('SELECT * FROM copyright WHERE ct_pk=$1', array($ctPk), __METHOD__ . '.cp');
     assertThat($updatedCp['content'], is(equalTo($content)));
 }
コード例 #21
0
ファイル: ShowJobsDao.php プロジェクト: DanielDobre/fossology
 /**
  * @brief Returns Estimated time using jobid
  * @param int $job_pk
  * @param string $jq_Type
  * @param float $filesPerSec
  * @param int $uploadId 
  * @return Returns empty if estimated time is 0 else returns time. 
  **/
 public function getEstimatedTime($job_pk, $jq_Type = '', $filesPerSec = 0, $uploadId = 0)
 {
     if (!empty($uploadId)) {
         $itemCount = $this->dbManager->getSingleRow("SELECT jq_itemsprocessed FROM jobqueue INNER JOIN job ON jq_job_fk=job_pk " . " WHERE jq_type LIKE 'ununpack' AND jq_end_bits ='1' AND job_upload_fk=\$1", array($uploadId), __METHOD__ . '.ununpack_might_be_in_other_job');
     } else {
         $itemCount = $this->dbManager->getSingleRow("SELECT jq_itemsprocessed FROM jobqueue WHERE jq_type LIKE 'ununpack' AND jq_end_bits ='1' AND jq_job_fk =\$1", array($job_pk), __METHOD__ . '.ununpack_must_be_in_this_job');
     }
     if (!empty($itemCount['jq_itemsprocessed'])) {
         $selectCol = "jq_type, jq_endtime, jq_starttime, jq_itemsprocessed";
         if (empty($jq_Type)) {
             $removeType = "jq_type NOT LIKE 'ununpack' AND jq_type NOT LIKE 'reportgen' AND jq_type NOT LIKE 'decider' AND";
             /* get starttime endtime and jobtype form jobqueue for a jobid except $removeType */
             $statementName = __METHOD__ . "{$selectCol}.{$removeType}";
             $this->dbManager->prepare($statementName, "SELECT {$selectCol} FROM jobqueue WHERE {$removeType} jq_job_fk =\$1 ORDER BY jq_type DESC");
             $result = $this->dbManager->execute($statementName, array($job_pk));
         } else {
             $statementName = __METHOD__ . "{$selectCol}.{$jq_Type}";
             $this->dbManager->prepare($statementName, "SELECT {$selectCol} FROM jobqueue WHERE jq_type LIKE '{$jq_Type}' AND jq_job_fk =\$1");
             $result = $this->dbManager->execute($statementName, array($job_pk));
         }
         $estimatedArray = array();
         // estimate time for each agent
         while ($row = $this->dbManager->fetchArray($result)) {
             $timeOfCompletion = 0;
             if (empty($row['jq_endtime']) && !empty($row['jq_starttime'])) {
                 // for agent started and not ended
                 if (empty($filesPerSec)) {
                     $burnTime = time() - strtotime($row['jq_starttime']);
                     $filesPerSec = $this->getNumItemsPerSec($row['jq_itemsprocessed'], $burnTime);
                 }
                 if (!empty($filesPerSec)) {
                     $timeOfCompletion = ($itemCount['jq_itemsprocessed'] - $row['jq_itemsprocessed']) / $filesPerSec;
                 }
                 array_push($estimatedArray, $timeOfCompletion);
             }
         }
         if (empty($estimatedArray)) {
             return "";
         } else {
             $estimatedTime = round(max($estimatedArray));
             // collecting max agent time in seconds
             return intval($estimatedTime / 3600) . gmdate(":i:s", $estimatedTime);
             // convert seconds to time and return
         }
     }
 }
コード例 #22
0
 public function runAndTestReport($uploadId = 1)
 {
     list($success, $output, $retCode) = $this->runnerCli->run($uploadId, $this->userId, $this->groupId, $jobId = 7);
     assertThat('cannot run runner', $success, equalTo(true));
     assertThat('report failed: "' . $output . '"', $retCode, equalTo(0));
     assertThat($this->getHeartCount($output), greaterThan(0));
     $row = $this->dbManager->getSingleRow("SELECT upload_fk,job_fk,filepath FROM reportgen WHERE job_fk = \$1", array($jobId), "reportFileName");
     assertThat($row, hasKeyValuePair('upload_fk', $uploadId));
     assertThat($row, hasKeyValuePair('job_fk', $jobId));
     $filepath = $row['filepath'];
     assertThat($filepath, endsWith('.rdf'));
     assertThat(file_exists($filepath), equalTo(true));
     $copyrightStatement = '*****@*****.**';
     assertThat(file_get_contents($filepath), stringContainsInOrder($copyrightStatement));
     $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
     $this->verifyRdf($filepath);
     unlink($filepath);
     $this->rmRepo();
 }
コード例 #23
0
ファイル: ui-view-info.php プロジェクト: rlintu/fossology
 /**
  * \brief Display the package info associated with
  * the rpm/debian package.
  */
 function ShowPackageInfo($Upload, $Item, $ShowMenu = 0)
 {
     $V = "";
     $Require = "";
     $MIMETYPE = "";
     $Count = 0;
     $rpm_info = array("Package" => "pkg_name", "Alias" => "pkg_alias", "Architecture" => "pkg_arch", "Version" => "version", "License" => "license", "Group" => "pkg_group", "Packager" => "packager", "Release" => "release", "BuildDate" => "build_date", "Vendor" => "vendor", "URL" => "url", "Summary" => "summary", "Description" => "description", "Source" => "source_rpm");
     $deb_binary_info = array("Package" => "pkg_name", "Architecture" => "pkg_arch", "Version" => "version", "Section" => "section", "Priority" => "priority", "Installed Size" => "installed_size", "Maintainer" => "maintainer", "Homepage" => "homepage", "Source" => "source", "Summary" => "summary", "Description" => "description");
     $deb_source_info = array("Format" => "format", "Source" => "source", "Binary" => "pkg_name", "Architecture" => "pkg_arch", "Version" => "version", "Maintainer" => "maintainer", "Uploaders" => "uploaders", "Standards-Version" => "standards_version");
     if (empty($Item) || empty($Upload)) {
         return;
     }
     /**********************************
        Check if pkgagent disabled
        ***********************************/
     $sql = "SELECT agent_enabled FROM agent WHERE agent_name ='pkgagent' order by agent_ts LIMIT 1;";
     $row = $this->dbManager->getSingleRow($sql, array(), __METHOD__ . "checkPkgagentDisabled");
     if (isset($row) && $row['agent_enabled'] == 'f') {
         return;
     }
     /**********************************
        Display package info
        **********************************/
     $text = _("Package Info");
     $V .= "<H2>{$text}</H2>\n";
     /* If pkgagent_ars table didn't exists, don't show the result. */
     $sql = "SELECT typlen  FROM pg_type where typname='pkgagent_ars' limit 1;";
     $this->dbManager->prepare(__METHOD__ . "displayPackageInfo", $sql);
     $result = $this->dbManager->execute(__METHOD__ . "displayPackageInfo", array());
     $numrows = pg_num_rows($result);
     $this->dbManager->freeResult($result);
     if ($numrows <= 0) {
         $V .= _("No data available. Use Jobs > Agents to schedule a pkgagent scan.");
         return $V;
     }
     /* If pkgagent_ars table didn't have record for this upload, don't show the result. */
     $agent_status = AgentARSList('pkgagent_ars', $Upload);
     if (empty($agent_status)) {
         /** schedule pkgagent */
         $V .= ActiveHTTPscript("Schedule");
         $V .= "<script language='javascript'>\n";
         $V .= "function Schedule_Reply()\n";
         $V .= "  {\n";
         $V .= "  if ((Schedule.readyState==4) && (Schedule.status==200))\n";
         $V .= "    document.getElementById('msgdiv').innerHTML = Schedule.responseText;\n";
         $V .= "  }\n";
         $V .= "</script>\n";
         $V .= "<form name='formy' method='post'>\n";
         $V .= "<div id='msgdiv'>\n";
         $V .= _("No data available.");
         $V .= "<input type='button' name='scheduleAgent' value='Schedule Agent'";
         $V .= "onClick='Schedule_Get(\"" . Traceback_uri() . "?mod=schedule_agent&upload={$Upload}&agent=agent_pkgagent \")'>\n";
         $V .= "</input>";
         $V .= "</div> \n";
         $V .= "</form>\n";
         return $V;
     }
     $sql = "SELECT mimetype_name\n        FROM uploadtree\n        INNER JOIN pfile ON uploadtree_pk = \$1\n        AND pfile_fk = pfile_pk\n        INNER JOIN mimetype ON pfile_mimetypefk = mimetype_pk;";
     $this->dbManager->prepare(__METHOD__ . "getMimetypeName", $sql);
     $result = $this->dbManager->execute(__METHOD__ . "getMimetypeName", array($Item));
     while ($row = pg_fetch_assoc($result)) {
         if (!empty($row['mimetype_name'])) {
             $MIMETYPE = $row['mimetype_name'];
         }
     }
     $this->dbManager->freeResult($result);
     /** RPM Package Info **/
     if ($MIMETYPE == "application/x-rpm") {
         $sql = "SELECT *\n                FROM pkg_rpm\n                INNER JOIN uploadtree ON uploadtree_pk = \$1\n                AND uploadtree.pfile_fk = pkg_rpm.pfile_fk;";
         $R = $this->dbManager->getSingleRow($sql, array($Item), __METHOD__ . "getRPMPackageInfo");
         if (!empty($R['source_rpm']) and trim($R['source_rpm']) != "(none)") {
             $V .= _("RPM Binary Package");
         } else {
             $V .= _("RPM Source Package");
         }
         $Count = 1;
         $V .= "<table border='1' name='pkginfo'>\n";
         $text = _("Item");
         $text1 = _("Type");
         $text2 = _("Value");
         $V .= "<tr><th width='5%'>{$text}</th><th width='20%'>{$text1}</th><th>{$text2}</th></tr>\n";
         if (!empty($R['pkg_pk'])) {
             $Require = $R['pkg_pk'];
             foreach ($rpm_info as $key => $value) {
                 $text = _($key);
                 $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                 $V .= "</td><td>" . htmlentities($R["{$value}"]) . "</td></tr>\n";
                 $Count++;
             }
             $sql = "SELECT * FROM pkg_rpm_req WHERE pkg_fk = \$1;";
             $this->dbManager->prepare(__METHOD__ . "getPkg_rpm_req", $sql);
             $result = $this->dbManager->execute(__METHOD__ . "getPkg_rpm_req", array($Require));
             while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) {
                 $text = _("Requires");
                 $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                 $Val = htmlentities($R['req_value']);
                 $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i", "<a href='\$1'>\$1</a>", $Val);
                 $V .= "</td><td>{$Val}</td></tr>\n";
                 $Count++;
             }
             $this->dbManager->freeResult($result);
         }
         $V .= "</table>\n";
     } else {
         if ($MIMETYPE == "application/x-debian-package") {
             $V .= _("Debian Binary Package\n");
             $sql = "SELECT *\n                FROM pkg_deb\n                INNER JOIN uploadtree ON uploadtree_pk = \$1\n                AND uploadtree.pfile_fk = pkg_deb.pfile_fk;";
             $R = $this->dbManager->getSingleRow($sql, array($Item), __METHOD__ . "debianBinaryPackageInfo");
             $Count = 1;
             $V .= "<table border='1'>\n";
             $text = _("Item");
             $text1 = _("Type");
             $text2 = _("Value");
             $V .= "<tr><th width='5%'>{$text}</th><th width='20%'>{$text1}</th><th>{$text2}</th></tr>\n";
             if ($R) {
                 $Require = $R['pkg_pk'];
                 foreach ($deb_binary_info as $key => $value) {
                     $text = _($key);
                     $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                     $V .= "</td><td>" . htmlentities($R["{$value}"]) . "</td></tr>\n";
                     $Count++;
                 }
                 pg_free_result($result);
                 $sql = "SELECT * FROM pkg_deb_req WHERE pkg_fk = \$1;";
                 $this->dbManager->prepare(__METHOD__ . "getPkg_rpm_req", $sql);
                 $result = $this->dbManager->execute(__METHOD__ . "getPkg_rpm_req", array($Require));
                 while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) {
                     $text = _("Depends");
                     $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                     $Val = htmlentities($R['req_value']);
                     $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i", "<a href='\$1'>\$1</a>", $Val);
                     $V .= "</td><td>{$Val}</td></tr>\n";
                     $Count++;
                 }
                 $this->dbManager->freeResult($result);
             }
             $V .= "</table>\n";
         } else {
             if ($MIMETYPE == "application/x-debian-source") {
                 $V .= _("Debian Source Package\n");
                 $sql = "SELECT *\n                FROM pkg_deb\n                INNER JOIN uploadtree ON uploadtree_pk = \$1\n                AND uploadtree.pfile_fk = pkg_deb.pfile_fk;";
                 $R = $this->dbManager->getSingleRow($sql, array($Item), __METHOD__ . "debianSourcePakcageInfo");
                 $Count = 1;
                 $V .= "<table border='1'>\n";
                 $text = _("Item");
                 $text1 = _("Type");
                 $text2 = _("Value");
                 $V .= "<tr><th width='5%'>{$text}</th><th width='20%'>{$text1}</th><th>{$text2}</th></tr>\n";
                 if ($R) {
                     $Require = $R['pkg_pk'];
                     foreach ($deb_source_info as $key => $value) {
                         $text = _($key);
                         $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                         $V .= "</td><td>" . htmlentities($R["{$value}"]) . "</td></tr>\n";
                         $Count++;
                     }
                     pg_free_result($result);
                     $sql = "SELECT * FROM pkg_deb_req WHERE pkg_fk = \$1;";
                     $this->dbManager->prepare(__METHOD__ . "getPkg_rpm_req", $sql);
                     $result = $this->dbManager->execute(__METHOD__ . "getPkg_rpm_req", array($Require));
                     while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) {
                         $text = _("Build-Depends");
                         $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                         $Val = htmlentities($R['req_value']);
                         $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i", "<a href='\$1'>\$1</a>", $Val);
                         $V .= "</td><td>{$Val}</td></tr>\n";
                         $Count++;
                     }
                     $this->dbManager->freeResult($result);
                 }
                 $V .= "</table>\n";
             } else {
                 /* Not a package */
                 return "";
             }
         }
     }
     return $V;
 }
コード例 #24
0
 /** @brief check if shortname or license text of this license is existing */
 private function isShortnameBlocked($rfId, $shortname, $text)
 {
     $sql = "SELECT count(*) from license_ref where rf_pk <> \$1 and (LOWER(rf_shortname) = LOWER(\$2) or (rf_text <> ''\n      and rf_text = \$3 and LOWER(rf_text) NOT LIKE 'license by nomos'))";
     $check_count = $this->dbManager->getSingleRow($sql, array($rfId, $shortname, $text), __METHOD__ . '.countLicensesByNomos');
     return 0 < $check_count['count'];
 }
コード例 #25
0
 public function getPublicPermission($uploadId)
 {
     $row = $this->dbManager->getSingleRow('SELECT public_perm FROM upload WHERE upload_pk=$1 LIMIT 1', array($uploadId), __METHOD__);
     return $row['public_perm'];
 }
コード例 #26
0
ファイル: user-add.php プロジェクト: rlintu/fossology
 /**
  * \brief Add a user.
  * 
  * \return NULL on success, string on failure.
  */
 function Add()
 {
     global $PG_CONN;
     if (!$PG_CONN) {
         DBconnect();
         if (!$PG_CONN) {
             $text = _("NO DB connection!");
             echo "<pre>{$text}\n</pre>";
         }
     }
     /* Get the parameters */
     $User = str_replace("'", "''", GetParm('username', PARM_TEXT));
     $User = trim($User);
     $Pass = GetParm('pass1', PARM_TEXT);
     $Pass2 = GetParm('pass2', PARM_TEXT);
     $Seed = rand() . rand();
     $Hash = sha1($Seed . $Pass);
     $Desc = str_replace("'", "''", GetParm('description', PARM_TEXT));
     $Perm = GetParm('permission', PARM_INTEGER);
     $Folder = GetParm('folder', PARM_INTEGER);
     $Email_notify = GetParm('enote', PARM_TEXT);
     $Email = str_replace("'", "''", GetParm('email', PARM_TEXT));
     $agentList = userAgents();
     $default_bucketpool_fk = GetParm('default_bucketpool_fk', PARM_INTEGER);
     /* Make sure username looks valid */
     if (empty($User)) {
         $text = _("Username must be specified. Not added.");
         return $text;
     }
     /* limit the user name size to 64 characters when creating an account */
     if (strlen($User) > 64) {
         $text = _("Username exceed 64 characters. Not added.");
         return $text;
     }
     /* Make sure password matches */
     if ($Pass != $Pass2) {
         $text = _("Passwords did not match. Not added.");
         return $text;
     }
     /* Make sure email looks valid */
     $Check = preg_replace("/[^a-zA-Z0-9@_.+-]/", "", $Email);
     if ($Check != $Email) {
         $text = _("Invalid email address.  Not added.");
         return $text;
     }
     /* See if the user already exists (better not!) */
     $row = $this->dbManager->getSingleRow("SELECT * FROM users WHERE user_name = \$1 LIMIT 1;", array($User), $stmt = __METHOD__ . ".getUserIfExisting");
     if (!empty($row['user_name'])) {
         $text = _("User already exists.  Not added.");
         return $text;
     }
     /* check email notification, if empty (box not checked), or if no email
      * specified for the user set to 'n'.
      */
     if (empty($Email_notify)) {
         $Email_notify = '';
     } elseif (empty($Email)) {
         $Email_notify = '';
     }
     $ErrMsg = add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk);
     return $ErrMsg;
 }
コード例 #27
0
ファイル: LicenseDao.php プロジェクト: DanielDobre/fossology
 public function updateCandidate($rf_pk, $shortname, $fullname, $rfText, $url, $readyformerge, $riskLvl)
 {
     $marydone = $this->dbManager->booleanToDb($readyformerge);
     $this->dbManager->getSingleRow('UPDATE license_candidate SET rf_shortname=$2, rf_fullname=$3, rf_text=$4, rf_url=$5, marydone=$6, rf_risk=$7 WHERE rf_pk=$1', array($rf_pk, $shortname, $fullname, $rfText, $url, $marydone, $riskLvl), __METHOD__);
 }
コード例 #28
0
ファイル: PackageDao.php プロジェクト: DanielDobre/fossology
 /**
  * @return Package
  */
 public function createPackage($packageName)
 {
     $statementName = __METHOD__;
     $row = $this->dbManager->getSingleRow("INSERT INTO package (package_name) VALUES(\$1) RETURNING package_pk", array($packageName), $statementName);
     return new Package(intval($row['package_pk']), $packageName, array());
 }
コード例 #29
0
ファイル: libschema.php プロジェクト: DanielDobre/fossology
 /**
  * @brief Make schema match $Filename.  This is a single transaction.
  * @param string $filename Schema file written by schema-export.php
  * @param bool $debug Turn on debugging (echo sql as it is being executed)
  * @param string $catalog Optional database name
  * @param array[] $migrateColumns array('tablename'=>array('col1','col2'),...) of columns which should not be deleted
  * @return false=success, on error return string with error message.
  **/
 function applySchema($filename = NULL, $debug = false, $catalog = 'fossology', $migrateColumns = array())
 {
     global $PG_CONN;
     // first check to make sure we don't already have the plpgsql language installed
     $sql_statement = "select lanname from pg_language where lanname = 'plpgsql'";
     $result = pg_query($PG_CONN, $sql_statement);
     if (!$result) {
         throw new Exception("Could not check the database for plpgsql language");
     }
     $plpgsql_already_installed = FALSE;
     if (pg_fetch_row($result)) {
         $plpgsql_already_installed = TRUE;
     }
     // then create language plpgsql if not already created
     if ($plpgsql_already_installed == FALSE) {
         $sql_statement = "CREATE LANGUAGE plpgsql";
         $result = pg_query($PG_CONN, $sql_statement);
         if (!$result) {
             throw new Exception("Could not create plpgsql language in the database");
         }
     }
     $this->debug = $debug;
     if (!file_exists($filename)) {
         $errMsg = "{$filename} does not exist.";
         return $errMsg;
     }
     $Schema = array();
     /* will be filled in next line */
     require $filename;
     /* this cause Fatal Error if the file does not exist. */
     $this->schema = $Schema;
     /* Very basic sanity check (so we don't delete everything!) */
     if (count($this->schema['TABLE']) < 5 || count($this->schema['SEQUENCE']) < 5 || count($this->schema['INDEX']) < 5 || count($this->schema['CONSTRAINT']) < 5) {
         $errMsg = "Schema from '{$filename}' appears invalid.";
         return $errMsg;
     }
     if (!$debug) {
         $result = $this->dbman->getSingleRow("show statement_timeout", array(), $stmt = __METHOD__ . '.getTimeout');
         $statementTimeout = $result['statement_timeout'];
         $this->dbman->queryOnce("SET statement_timeout = 0", $stmt = __METHOD__ . '.setTimeout');
     }
     $this->applyOrEchoOnce('BEGIN');
     $this->getCurrSchema();
     $errlev = error_reporting(E_ERROR | E_WARNING | E_PARSE);
     $this->applySequences();
     $this->applyTables();
     $this->applyInheritedRelations();
     $this->updateSequences();
     $this->applyViews();
     $this->dropConstraints();
     /* Reload current since the CASCADE may have changed things */
     $this->getCurrSchema();
     /* constraints and indexes are linked, recheck */
     $this->dropIndexes();
     $this->applyIndexes();
     $this->applyConstraints();
     error_reporting($errlev);
     /* return to previous error reporting level */
     $this->makeFunctions();
     /* Reload current since CASCADE during migration may have changed things */
     $this->getCurrSchema();
     $this->dropViews($catalog);
     foreach ($this->currSchema['TABLE'] as $table => $columns) {
         $skipColumns = array_key_exists($table, $migrateColumns) ? $migrateColumns[$table] : array();
         $dropColumns = array_diff(array_keys($columns), $skipColumns);
         $this->dropColumnsFromTable($dropColumns, $table);
     }
     $this->applyOrEchoOnce('COMMIT');
     flush();
     ReportCachePurgeAll();
     if (!$debug) {
         $this->dbman->getSingleRow("SET statement_timeout = {$statementTimeout}", array(), $stmt = __METHOD__ . '.resetTimeout');
         print "DB schema has been updated for {$catalog}.\n";
     } else {
         print "These queries could update DB schema for {$catalog}.\n";
     }
     return false;
 }
コード例 #30
0
ファイル: UploadDao.php プロジェクト: rlintu/fossology
 /**
  * @param int $itemId
  * @param string $uploadId
  * @param string $uploadtreeTablename
  * @return array
  */
 public function getFatItemArray($itemId, $uploadId, $uploadtreeTablename)
 {
     $sqlChildrenOf = "SELECT COUNT(*) FROM {$uploadtreeTablename} s \n         WHERE ufile_mode&(1<<28)=0 and s.upload_fk=\$2 AND s.realparent=";
     $sql = "WITH RECURSIVE item_path (item_id,num_children,depth,ufile_mode,ufile_name) AS (\n        SELECT uploadtree_pk item_id, ({$sqlChildrenOf} \$1) num_children, 0 depth, ufile_mode, ufile_name\n          FROM {$uploadtreeTablename} WHERE upload_fk=\$2 AND uploadtree_pk=\$1\n        UNION\n        SELECT uploadtree_pk item_id, ({$sqlChildrenOf} ut.uploadtree_pk) num_children,\n               item_path.depth+1 depth, ut.ufile_mode, item_path.ufile_name||'/'||ut.ufile_name ufile_name\n          FROM {$uploadtreeTablename} ut INNER JOIN item_path ON item_id=ut.realparent\n          WHERE upload_fk=\$2 AND ut.ufile_mode&(1<<28)=0 AND num_children<2\n        )\n        SELECT * FROM item_path WHERE num_children!=1 OR ufile_mode&(1<<29)=0 ORDER BY depth DESC LIMIT 1";
     return $this->dbManager->getSingleRow($sql, array($itemId, $uploadId), __METHOD__ . $uploadtreeTablename);
 }