<commit_before><?php
	#
	# $Id: ports.php,v 1.1.2.37 2003-09-23 13:25:20 dan Exp $
	#
	# Copyright (c) 1998-2003 DVL Software Limited
	#


// base class for Port
class Port {

	// set on new
	var $dbh;

	// from the ports table
	var $id;
	var $element_id;
	var $category_id;
	var $short_description;
	var $long_description;
	var $version;
	var $revision;
	var $maintainer;
	var $homepage;
	var $master_sites;
	var $extract_suffix;
	var $package_exists;
	var $depends_build;
	var $depends_run;
	var $last_commit_id;
	var $found_in_index;
	var $forbidden;
	var $broken;
	var $date_added;
	var $categories;

	// derived or from other tables
	var $category;
	var $port;
	var $needs_refresh;
	var $status;
	var $updated;	// timestamp of last update

	var $onwatchlist;	// count of how many watch lists is this port on for this user. 
						// not actually fetched directly by this class.
						// normally used only if you've specified it in your own SQL.

	// not always present/set
	var $update_description;

	// so far used by ports-deleted.php and include/list-of-ports.php
	var $message_id;
	var $encoding_losses;

	// needed for fetch by category
	var $LocalResult;

	var $committer; 

	function Port($dbh) {
		$this->dbh	= $dbh;
	}

	function _PopulateValues($myrow) {
		$this->id                 = $myrow["id"];
		$this->element_id         = $myrow["element_id"];
		$this->category_id        = $myrow["category_id"];
		$this->short_description  = $myrow["short_description"];
		$this->long_description   = $myrow["long_description"];
		$this->version            = $myrow["version"];
		$this->revision           = $myrow["revision"];
		$this->maintainer         = $myrow["maintainer"];
		$this->homepage           = $myrow["homepage"];
		$this->master_sites       = $myrow["master_sites"];
		$this->extract_suffix     = $myrow["extract_suffix"];
		$this->package_exists     = $myrow["package_exists"];
		$this->depends_build      = $myrow["depends_build"];
		$this->depends_run        = $myrow["depends_run"];
		$this->last_commit_id     = $myrow["last_commit_id"];
		$this->found_in_index     = $myrow["found_in_index"];
		$this->forbidden          = $myrow["forbidden"];
		$this->broken             = $myrow["broken"];
		$this->date_added         = $myrow["date_added"];
		$this->categories         = $myrow["categories"];

		$this->port               = $myrow["port"];
		$this->category           = $myrow["category"];
		if (In_Array('needs_refresh', $myrow)) $this->needs_refresh      = $myrow["needs_refresh"];
		$this->status             = $myrow["status"];
		if (In_Array('updated',       $myrow)) $this->updated            = $myrow["updated"];

		if (In_Array('onwatchlist',   $myrow)) $this->onwatchlist        = $myrow["onwatchlist"];

		if (In_Array('update_description', $myrow)) $this->update_description = $myrow["update_description"];
		if (In_Array('message_id',         $myrow)) $this->message_id         = $myrow["message_id"];
		if (In_Array('encoding_losses',    $myrow)) $this->encoding_losses    = $myrow["encoding_losses"];
		if (In_Array('committer',          $myrow)) $this->committer          = $myrow["committer"];

		// We might be looking at category lang.  japanese/gawk is listed in both japanese and lang.
		// So when looking at lang, we don't want to say, Also listed in lang...  
		//
		$this->category_looking_at= $myrow["category_looking_at"];
	}

	function FetchByPartialName($pathname, $UserID = 0) {

		# I THINK THIS FUNCTION IS NOT REQUIRED.

		$Debug = 0;

		# fetch a single port based on pathname.
		# e.g. net/samba
		#
		# It will not bring back any commit information.

		#
		# first, we get the element relating to this port
		#
		$element = new Element($this->dbh);
      $element->FetchByName($pathname);
      
      # * * * * * * * * * * * * * * * * * * * * * * * * *
      # Now that we have the ID, we should call FetchByID!
      # * * * * * * * * * * * * * * * * * * * * * * * * *

		if ($Debug) echo "into FetchByPartialName with $pathname<BR>";

		if (IsSet($element->id)) {
			$this->element_id = $element->id;

			$sql = "
select ports.id,
       ports.element_id,
       ports.category_id       as category_id, 
       ports.short_description as short_description, 
       ports.long_description, 
       ports.version           as version, 
       ports.revision          as revision, 
       ports.maintainer, 
       ports.homepage, 
       ports.master_sites, 
       ports.extract_suffix, 
       ports.package_exists, 
       ports.depends_build, 
       ports.depends_run, 
       ports.last_commit_id, 
       ports.found_in_index, 
       ports.forbidden, 
       ports.broken, 
       to_char(ports.date_added - SystemTimeAdjust(), 'DD Mon YYYY HH24:MI:SS') as date_added, 
       ports.categories as categories,
	    element.name     as port, 
	    categories.name  as category,
	    element.status ";

			if ($UserID) {
				$sql .= ",
	        TEMP.onwatchlist";
	      }

	      $sql .= "
       from categories, element, ports ";

			if ($UserID) {
				$sql .= "
	      LEFT OUTER JOIN
	 (SELECT element_id as wle_element_id, COUNT(watch_list_id) as onwatchlist
	    FROM watch_list JOIN watch_list_element 
	        ON watch_list.id      = watch_list_element.watch_list_id
	       AND watch_list.user_id = $UserID
	  GROUP BY element_id) AS TEMP
	       ON TEMP.wle_element_id = ports.element_id";
	      }
	

			$sql .= " WHERE element.id        = $this->element_id 
			            and ports.category_id = categories.id 
			            and ports.element_id  = element.id ";


			if ($Debug) {
				echo "<pre>$sql</pre>";
			}

	      $result = pg_exec($this->dbh, $sql);
			if ($result) {
				$numrows = pg_numrows($result);
				if ($numrows == 1) {
					if ($Debug) echo "fetched by ID succeeded<BR>";
					$myrow = pg_fetch_array ($result);
					$this->_PopulateValues($myrow);
				} else {
					echo "Ports::FetchByPartialName I'm concerned I got $numrows from that.<BR>$sql<BR>";
				}
			} else {
				echo 'pg_exec failed: ' . $sql;
			}
		} else {
			echo 'ports FetchByPartialName for $path failed';
		}
	}

	function FetchByID($id, $UserID = 0) {
		# fetch a single port based on id
		# used by missing-port.php<commit_msg>rename FetchByPartialName to FetchByElementID for use by missing-ort.php<commit_after><?php
	#
	# $Id: ports.php,v 1.1.2.38 2003-09-24 17:54:44 dan Exp $
	#
	# Copyright (c) 1998-2003 DVL Software Limited
	#


// base class for Port
class Port {

	// set on new
	var $dbh;

	// from the ports table
	var $id;
	var $element_id;
	var $category_id;
	var $short_description;
	var $long_description;
	var $version;
	var $revision;
	var $maintainer;
	var $homepage;
	var $master_sites;
	var $extract_suffix;
	var $package_exists;
	var $depends_build;
	var $depends_run;
	var $last_commit_id;
	var $found_in_index;
	var $forbidden;
	var $broken;
	var $date_added;
	var $categories;

	// derived or from other tables
	var $category;
	var $port;
	var $needs_refresh;
	var $status;
	var $updated;	// timestamp of last update

	var $onwatchlist;	// count of how many watch lists is this port on for this user. 
						// not actually fetched directly by this class.
						// normally used only if you've specified it in your own SQL.

	// not always present/set
	var $update_description;

	// so far used by ports-deleted.php and include/list-of-ports.php
	var $message_id;
	var $encoding_losses;

	// needed for fetch by category
	var $LocalResult;

	var $committer; 

	function Port($dbh) {
		$this->dbh	= $dbh;
	}

	function _PopulateValues($myrow) {
		$this->id                 = $myrow["id"];
		$this->element_id         = $myrow["element_id"];
		$this->category_id        = $myrow["category_id"];
		$this->short_description  = $myrow["short_description"];
		$this->long_description   = $myrow["long_description"];
		$this->version            = $myrow["version"];
		$this->revision           = $myrow["revision"];
		$this->maintainer         = $myrow["maintainer"];
		$this->homepage           = $myrow["homepage"];
		$this->master_sites       = $myrow["master_sites"];
		$this->extract_suffix     = $myrow["extract_suffix"];
		$this->package_exists     = $myrow["package_exists"];
		$this->depends_build      = $myrow["depends_build"];
		$this->depends_run        = $myrow["depends_run"];
		$this->last_commit_id     = $myrow["last_commit_id"];
		$this->found_in_index     = $myrow["found_in_index"];
		$this->forbidden          = $myrow["forbidden"];
		$this->broken             = $myrow["broken"];
		$this->date_added         = $myrow["date_added"];
		$this->categories         = $myrow["categories"];

		$this->port               = $myrow["port"];
		$this->category           = $myrow["category"];
		if (In_Array('needs_refresh', $myrow)) $this->needs_refresh      = $myrow["needs_refresh"];
		$this->status             = $myrow["status"];
		if (In_Array('updated',       $myrow)) $this->updated            = $myrow["updated"];

		if (In_Array('onwatchlist',   $myrow)) $this->onwatchlist        = $myrow["onwatchlist"];

		if (In_Array('update_description', $myrow)) $this->update_description = $myrow["update_description"];
		if (In_Array('message_id',         $myrow)) $this->message_id         = $myrow["message_id"];
		if (In_Array('encoding_losses',    $myrow)) $this->encoding_losses    = $myrow["encoding_losses"];
		if (In_Array('committer',          $myrow)) $this->committer          = $myrow["committer"];

		// We might be looking at category lang.  japanese/gawk is listed in both japanese and lang.
		// So when looking at lang, we don't want to say, Also listed in lang...  
		//
		$this->category_looking_at= $myrow["category_looking_at"];
	}

	function FetchByElementID($element_id, $UserID = 0) {

		$Debug = 0;

		# fetch a single port based on element_id.
		# e.g. net/samba
		#
		# It will not bring back any commit information.

		$this->element_id = $element_id;

		$sql = "
select ports.id,
       ports.element_id,
       ports.category_id       as category_id, 
       ports.short_description as short_description, 
       ports.long_description, 
       ports.version           as version, 
       ports.revision          as revision, 
       ports.maintainer, 
       ports.homepage, 
       ports.master_sites, 
       ports.extract_suffix, 
       ports.package_exists, 
       ports.depends_build, 
       ports.depends_run, 
       ports.last_commit_id, 
       ports.found_in_index, 
       ports.forbidden, 
       ports.broken, 
       to_char(ports.date_added - SystemTimeAdjust(), 'DD Mon YYYY HH24:MI:SS') as date_added, 
       ports.categories as categories,
	    element.name     as port, 
	    categories.name  as category,
	    element.status ";

		if ($UserID) {
			$sql .= ",
	        TEMP.onwatchlist";
		}

		$sql .= "
       from categories, element, ports ";

		if ($UserID) {
			$sql .= "
	      LEFT OUTER JOIN
	 (SELECT element_id as wle_element_id, COUNT(watch_list_id) as onwatchlist
	    FROM watch_list JOIN watch_list_element 
	        ON watch_list.id      = watch_list_element.watch_list_id
	       AND watch_list.user_id = $UserID
	  GROUP BY element_id) AS TEMP
	       ON TEMP.wle_element_id = ports.element_id";
		}
	

		$sql .= " WHERE element.id        = $this->element_id 
			        and ports.category_id = categories.id 
			        and ports.element_id  = element.id ";


		if ($Debug) {
			echo "<pre>$sql</pre>";
		}

		$result = pg_exec($this->dbh, $sql);
		if ($result) {
			$numrows = pg_numrows($result);
			if ($numrows == 1) {
				if ($Debug) echo "fetched by ID succeeded<BR>";
				$myrow = pg_fetch_array ($result);
				$this->_PopulateValues($myrow);
			} else {
				echo "Ports::FetchByPartialName I'm concerned I got $numrows from that.<BR>$sql<BR>";
			}
		} else {
			echo 'pg_exec failed: ' . $sql;
		}
	}

	function FetchByID($id, $UserID = 0) {
		# fetch a single port based on id
		# used by missing-port.php
{'fraction_non_alphanumeric': 0.13743279569892472, 'fraction_numerical': 0.005544354838709678, 'mean_word_length': 2.743710691823899, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 90, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '510268', 'n_tokens_mistral': 4435, 'n_tokens_neox': 3979, 'n_words': 930}