index : archweb32 | |
Archlinux32 website | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | lib/.htaccess | 1 | ||||
-rw-r--r-- | lib/format.php | 58 | ||||
-rw-r--r-- | lib/helper.php | 195 | ||||
-rw-r--r-- | lib/http.php | 17 | ||||
-rw-r--r-- | lib/mysql-joins.php | 1438 | ||||
-rw-r--r-- | lib/mysql.php | 90 | ||||
-rw-r--r-- | lib/style.php | 74 |
diff --git a/lib/.htaccess b/lib/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/lib/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/lib/format.php b/lib/format.php new file mode 100644 index 0000000..00e8296 --- /dev/null +++ b/lib/format.php @@ -0,0 +1,58 @@ +<?php + +# do not include twice +if (function_exists("export_as_requested")) + return; + +require_once "../init.php"; +include_once BASE . "/lib/http.php"; + +function export_as_requested($content) { + if (isset($content["All"])) { + $content["json"]=$content["All"]; + $content["tsv"]=$content["All"]; + unset($content["All"]); + } + if (isset($content["json"]) && isset($_GET["json"])) { + header ("Content-type: application/json"); + print json_encode( + $content["json"], + JSON_UNESCAPED_SLASHES + ); + } elseif (isset($content["tsv"]) && isset($_GET["tsv"])) { + header ("Content-type: text/tab-separated-values"); + if (! isset($_GET["no-headers"])) + print implode("\t",array_keys($content["tsv"][0])) . "\n"; + print implode( + "", + array_map( + function($row){ + return implode("\t",$row) . "\n"; + }, + $content["tsv"] + ) + ); + } else { + throw_http_error( + 406, + "Not Acceptable", + implode( + "<br>\n", + array_merge( + array( + "Unknown output format.", + "Accepted:" + ), + array_map( + function($type){ + return "<a href=\"?" . $type . "\">" . $type . "</a>"; + }, + array_keys( + $content + ) + ) + ) + ) + ); + } +} diff --git a/lib/helper.php b/lib/helper.php new file mode 100644 index 0000000..8296cd9 --- /dev/null +++ b/lib/helper.php @@ -0,0 +1,195 @@ +<?php + +# do not include twice +if (function_exists("format_time_duration")) + return; + +require_once "../init.php"; + +function format_time_duration($val) { + $val = floor($val); + $result = ""; + $result = + sprintf( + "%02d", + $val % 60 + ); + $val = floor($val / 60); + if ($val == 0) + return $result; + $result = + sprintf( + "%02d:%s", + $val % 60, + $result + ); + $val = floor($val / 60); + if ($val == 0) + return $result; + $result = + sprintf( + "%d:%s", + $val % 24, + $result + ); + $val = floor($val / 24); + if ($val == 0) + return $result; + $tmp = $val % 7; + $printed_conjunction = true; + if ($tmp > 1) + $result = + sprintf( + "%d days and %s", + $tmp, + $result + ); + elseif ($tmp == 1) + $result = + sprintf( + "%d day and %s", + $tmp, + $result + ); + else + $printed_conjunction = false; + $val = floor($val / 7); + if ($val == 0) + return $result; + if ($printed_conjunction) + $result = + sprintf( + ", %s", + $result + ); + else + $result = + sprintf( + " and %s", + $result + ); + if ($val>1) + $result = + sprintf( + "%d weeks%s", + $val, + $result + ); + else + $result = + sprintf( + "%d week%s", + $val, + $result + ); + return $result; +}; + +function git_url($repository,$type,$commit,$path,$line = null,$commit_is_hash = null) { + global $git_available; + if (!isset($git_available)) { + $memcache = new Memcache; + $memcache->connect('localhost', 11211) or die ('Memcached Connection Error'); + $git_available = $memcache->get('git_available'); + if ($git_available === false) { + $git_available = + preg_match( + "/ 200 OK$/", + get_headers("https://git.archlinux32.org/archlinux32/packages")[0] + ); + $memcache->set('git_available',$git_available,0,120); + }; + $git_available = $git_available == 1; + } + if (!isset($commit_is_hash)) + $commit_is_hash = preg_match("/^[0-9a-f]{40}$/",$commit)==1; + if ($git_available) { + if (isset($line)) + $line = "#L" . $line; + else + $line = ""; + if ($commit_is_hash) + $commit = "commit/" . $commit; + else + $commit = "branch/" . $commit; + switch ($type) { + case "tree": + return + "https://git.archlinux32.org/archlinux32/" . + $repository . + "/src/" . + $commit . + "/" . + $path . + $line; + case "log": + return + "https://git.archlinux32.org/archlinux32/" . + $repository . + "/commits/" . + $commit . + "/" . + $path . + $line; + } + + } else { + if (isset($line)) + $line = "#n" . $line; + else + $line = ""; + if ($commit_is_hash) + $commit = "?id=" . $commit; + else + $commit = "?h=" . $commit; + switch ($type) { + case "tree": + return + "https://git2.archlinux32.org/Archlinux32/" . + $repository . + "/tree/" . + $path . + $commit . + $line; + case "log": + return + "https://git2.archlinux32.org/Archlinux32/" . + $repository . + "/log/" . + $path . + $commit . + $line; + } + }; +}; + +function if_unset($array, $index, $default) { + if (isset($array[$index])) + return $array[$index]; + else + return $default; +}; + +function site_is_reachable($url) { + $scd = stream_context_get_default(); + stream_context_set_default(array('timeout' => 10)); + $headers = get_headers($url); + stream_context_set_default($scd); + if (is_array($headers)) + foreach ($headers as $header) { + if (!(strpos($header, 'HTTP/') === 0)) + continue; + if (explode(' ', $header)[1] == '200') + return true; + return false; + } + return false; +} + +function add_fancy_unit($value, $unit) { + $suffixes = array("z", "y", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "Y", "Z"); + if ($value==0) + return $value . " " . $unit; + $exponent = max(0,min(count($suffixes)-1,round(log(abs($value))/log(1024)-1))); + return sprintf("%.2f %s%s", $value / pow(1024,$exponent), $suffixes[8 + $exponent], $unit); +} diff --git a/lib/http.php b/lib/http.php new file mode 100644 index 0000000..9b63337 --- /dev/null +++ b/lib/http.php @@ -0,0 +1,17 @@ +<?php + +# do not include twice +if (function_exists("throw_http_error")) + return; + +function throw_http_error($error_number, $error_message, $extra_message = "") { + header("Status: " . $error_number . " " . $error_message); + print "Error " . $error_number . ": " . $error_message . "\n"; + if ($extra_message != "") + print "<br>\n" . $extra_message; + die(); +}; + +function die_500($message) { + throw_http_error(500, "Internal Server Error", $message); +}; diff --git a/lib/mysql-joins.php b/lib/mysql-joins.php new file mode 100644 index 0000000..751f1a0 --- /dev/null +++ b/lib/mysql-joins.php @@ -0,0 +1,1438 @@ +<?php + +/** + * generate below content with + * php mysql-joins.php + * executed from the builder directory + **/ + +if (!isset($_SERVER["SERVER_ADDR"])) { + foreach (array('.', '../builder', '../../builder') as $base_dir) + if (file_exists($base_dir . '/lib/mysql-functions')) { + putenv('base_dir=' . $base_dir); + break; + } + $new_output = + "\n" . + trim( + shell_exec( + '. ${base_dir}/lib/mysql-functions;' . + 'declare -f $(' . + 'declare -F | cut -d" " -f3 | grep "^mysql_join_[a-z]" | grep -v "with_version"' . + ')' + ) + ); + $output = ""; + $i = 5; + while ((strcmp($new_output,$output)!=0) && ($i > 0)) { + $output = $new_output; + $new_output = + preg_replace( + array( + '/ \[ -n "([^"]+)" \]; then/', + '/(\n\s*printf '."'[^'%]*)%s([^']*'".') "(\$[0-9]+)"/', + '/(\n\s*if [^\n]*)(\n([^\n]*;\n)+\s*)(else)(\n([^\n]*;\n)+\s*)fi;?\n/', + '/(\n\s*if [^\n]*)(\n([^\n]*;\n)+\s*)fi;?\n/' + ), + array( + ' (!empty(\1))', + '\1'."'".'.\3.'."'".'\2', + '\1 {\2} \4 {\5}'."\n", + '\1 {\2}'."\n" + ), + $output + ); + $i--; + } + $output = + preg_replace( + array( + '/\$1/', + '/\$2/', + '/(\n)(\S+) \(\)\s*\n{/', + '/(\n})/', + '/(\s)printf(\s)/' + ), + array( + '$table_left', + '$table_right', + '\1function \2 ($table_left="", $table_right="") {'."\n".' $result = "";', + "\n".' return $result;\1', + '\1$result .=\2' + ), + $output + ); + print $output . "\n"; + die(); +} + +// auto-generated content below + +function mysql_join_allowed_email_actions_email_actions ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `email_actions`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`action`='; + } else { + $result .= ' ON `allowed_email_actions`.`action`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`email_actions`.`id`'; + } + return $result; +} +function mysql_join_allowed_email_actions_gpg_keys ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `gpg_keys`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`gpg_key`='; + } else { + $result .= ' ON `allowed_email_actions`.`gpg_key`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`gpg_keys`.`id`'; + } + return $result; +} +function mysql_join_architectures_binary_packages ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `architectures`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`architecture`'; + } else { + $result .= '`binary_packages`.`architecture`'; + } + return $result; +} +function mysql_join_architectures_build_assignments ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_assignments`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `architectures`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`architecture`'; + } else { + $result .= '`build_assignments`.`architecture`'; + } + return $result; +} +function mysql_join_architectures_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `architectures`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`architecture`'; + } else { + $result .= '`repositories`.`architecture`'; + } + return $result; +} +function mysql_join_binary_packages_architectures ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `architectures`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`architecture`='; + } else { + $result .= ' ON `binary_packages`.`architecture`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`architectures`.`id`'; + } + return $result; +} +function mysql_join_binary_packages_binary_packages_in_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages_in_repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `binary_packages`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`package`'; + } else { + $result .= '`binary_packages_in_repositories`.`package`'; + } + return $result; +} +function mysql_join_binary_packages_build_assignments ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_assignments`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`build_assignment`='; + } else { + $result .= ' ON `binary_packages`.`build_assignment`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`build_assignments`.`id`'; + } + return $result; +} +function mysql_join_binary_packages_build_dependency_loops ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_dependency_loops`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`build_assignment`='; + } else { + $result .= ' ON `binary_packages`.`build_assignment`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`build_assignment`'; + } else { + $result .= '`build_dependency_loops`.`build_assignment`'; + } + return $result; +} +function mysql_join_binary_packages_build_slaves ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_slaves`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`build_assignment`='; + } else { + $result .= ' ON `binary_packages`.`build_assignment`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`currently_building`'; + } else { + $result .= '`build_slaves`.`currently_building`'; + } + return $result; +} +function mysql_join_binary_packages_dependencies ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `dependencies`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `binary_packages`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`dependent`'; + } else { + $result .= '`dependencies`.`dependent`'; + } + return $result; +} +function mysql_join_binary_packages_in_repositories_binary_packages ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`package`='; + } else { + $result .= ' ON `binary_packages_in_repositories`.`package`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`binary_packages`.`id`'; + } + return $result; +} +function mysql_join_binary_packages_in_repositories_dependencies ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `dependencies`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`package`='; + } else { + $result .= ' ON `binary_packages_in_repositories`.`package`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`dependent`'; + } else { + $result .= '`dependencies`.`dependent`'; + } + return $result; +} +function mysql_join_binary_packages_in_repositories_install_target_providers ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `install_target_providers`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`package`='; + } else { + $result .= ' ON `binary_packages_in_repositories`.`package`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`package`'; + } else { + $result .= '`install_target_providers`.`package`'; + } + return $result; +} +function mysql_join_binary_packages_in_repositories_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`repository`='; + } else { + $result .= ' ON `binary_packages_in_repositories`.`repository`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`repositories`.`id`'; + } + return $result; +} +function mysql_join_binary_packages_install_target_providers ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `install_target_providers`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `binary_packages`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`package`'; + } else { + $result .= '`install_target_providers`.`package`'; + } + return $result; +} +function mysql_join_build_assignments_architectures ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `architectures`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`architecture`='; + } else { + $result .= ' ON `build_assignments`.`architecture`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`architectures`.`id`'; + } + return $result; +} +function mysql_join_build_assignments_binary_packages ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `build_assignments`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`build_assignment`'; + } else { + $result .= '`binary_packages`.`build_assignment`'; + } + return $result; +} +function mysql_join_build_assignments_build_dependency_loops ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_dependency_loops`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `build_assignments`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`build_assignment`'; + } else { + $result .= '`build_dependency_loops`.`build_assignment`'; + } + return $result; +} +function mysql_join_build_assignments_build_slaves ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_slaves`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `build_assignments`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`currently_building`'; + } else { + $result .= '`build_slaves`.`currently_building`'; + } + return $result; +} +function mysql_join_build_assignments_failed_builds ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `failed_builds`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `build_assignments`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`build_assignment`'; + } else { + $result .= '`failed_builds`.`build_assignment`'; + } + return $result; +} +function mysql_join_build_assignments_package_sources ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `package_sources`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`package_source`='; + } else { + $result .= ' ON `build_assignments`.`package_source`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`package_sources`.`id`'; + } + return $result; +} +function mysql_join_build_dependency_loops_binary_packages ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`build_assignment`='; + } else { + $result .= ' ON `build_dependency_loops`.`build_assignment`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`build_assignment`'; + } else { + $result .= '`binary_packages`.`build_assignment`'; + } + return $result; +} +function mysql_join_build_dependency_loops_build_assignments ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_assignments`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`build_assignment`='; + } else { + $result .= ' ON `build_dependency_loops`.`build_assignment`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`build_assignments`.`id`'; + } + return $result; +} +function mysql_join_build_slaves_binary_packages ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`currently_building`='; + } else { + $result .= ' ON `build_slaves`.`currently_building`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`build_assignment`'; + } else { + $result .= '`binary_packages`.`build_assignment`'; + } + return $result; +} +function mysql_join_build_slaves_build_assignments ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_assignments`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`currently_building`='; + } else { + $result .= ' ON `build_slaves`.`currently_building`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`build_assignments`.`id`'; + } + return $result; +} +function mysql_join_build_slaves_failed_builds ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `failed_builds`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `build_slaves`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`build_slave`'; + } else { + $result .= '`failed_builds`.`build_slave`'; + } + return $result; +} +function mysql_join_build_slaves_ssh_keys ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `ssh_keys`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`ssh_key`='; + } else { + $result .= ' ON `build_slaves`.`ssh_key`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`ssh_keys`.`id`'; + } + return $result; +} +function mysql_join_build_slaves_ssh_log ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `ssh_log`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `build_slaves`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`build_slave`'; + } else { + $result .= '`ssh_log`.`build_slave`'; + } + return $result; +} +function mysql_join_dependencies_binary_packages ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`dependent`='; + } else { + $result .= ' ON `dependencies`.`dependent`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`binary_packages`.`id`'; + } + return $result; +} +function mysql_join_dependencies_binary_packages_in_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages_in_repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`dependent`='; + } else { + $result .= ' ON `dependencies`.`dependent`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`package`'; + } else { + $result .= '`binary_packages_in_repositories`.`package`'; + } + return $result; +} +function mysql_join_dependencies_dependency_types ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `dependency_types`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`dependency_type`='; + } else { + $result .= ' ON `dependencies`.`dependency_type`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`dependency_types`.`id`'; + } + return $result; +} +function mysql_join_dependencies_install_target_providers ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `install_target_providers`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`depending_on`='; + } else { + $result .= ' ON `dependencies`.`depending_on`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`install_target`'; + } else { + $result .= '`install_target_providers`.`install_target`'; + } + return $result; +} +function mysql_join_dependencies_install_targets ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `install_targets`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`depending_on`='; + } else { + $result .= ' ON `dependencies`.`depending_on`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`install_targets`.`id`'; + } + return $result; +} +function mysql_join_dependencies_versions ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `versions`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`version`='; + } else { + $result .= ' ON `dependencies`.`version`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`versions`.`id`'; + } + return $result; +} +function mysql_join_dependency_types_dependencies ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `dependencies`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `dependency_types`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`dependency_type`'; + } else { + $result .= '`dependencies`.`dependency_type`'; + } + return $result; +} +function mysql_join_email_actions_allowed_email_actions ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `allowed_email_actions`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `email_actions`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`action`'; + } else { + $result .= '`allowed_email_actions`.`action`'; + } + return $result; +} +function mysql_join_email_actions_email_log ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `email_log`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `email_actions`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`action`'; + } else { + $result .= '`email_log`.`action`'; + } + return $result; +} +function mysql_join_email_log_email_actions ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `email_actions`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`action`='; + } else { + $result .= ' ON `email_log`.`action`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`email_actions`.`id`'; + } + return $result; +} +function mysql_join_email_log_gpg_keys ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `gpg_keys`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`gpg_key`='; + } else { + $result .= ' ON `email_log`.`gpg_key`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`gpg_keys`.`id`'; + } + return $result; +} +function mysql_join_fail_reasons_failed_builds ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `failed_builds`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `fail_reasons`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`reason`'; + } else { + $result .= '`failed_builds`.`reason`'; + } + return $result; +} +function mysql_join_failed_builds_build_assignments ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_assignments`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`build_assignment`='; + } else { + $result .= ' ON `failed_builds`.`build_assignment`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`build_assignments`.`id`'; + } + return $result; +} +function mysql_join_failed_builds_build_slaves ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_slaves`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`build_slave`='; + } else { + $result .= ' ON `failed_builds`.`build_slave`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`build_slaves`.`id`'; + } + return $result; +} +function mysql_join_failed_builds_fail_reasons ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `fail_reasons`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`reason`='; + } else { + $result .= ' ON `failed_builds`.`reason`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`fail_reasons`.`id`'; + } + return $result; +} +function mysql_join_git_repositories_upstream_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `upstream_repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `git_repositories`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`git_repository`'; + } else { + $result .= '`upstream_repositories`.`git_repository`'; + } + return $result; +} +function mysql_join_gpg_keys_allowed_email_actions ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `allowed_email_actions`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `gpg_keys`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`gpg_key`'; + } else { + $result .= '`allowed_email_actions`.`gpg_key`'; + } + return $result; +} +function mysql_join_gpg_keys_email_log ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `email_log`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `gpg_keys`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`gpg_key`'; + } else { + $result .= '`email_log`.`gpg_key`'; + } + return $result; +} +function mysql_join_gpg_keys_persons ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `persons`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`owner`='; + } else { + $result .= ' ON `gpg_keys`.`owner`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`persons`.`id`'; + } + return $result; +} +function mysql_join_install_target_providers_binary_packages ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`package`='; + } else { + $result .= ' ON `install_target_providers`.`package`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`binary_packages`.`id`'; + } + return $result; +} +function mysql_join_install_target_providers_binary_packages_in_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages_in_repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`package`='; + } else { + $result .= ' ON `install_target_providers`.`package`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`package`'; + } else { + $result .= '`binary_packages_in_repositories`.`package`'; + } + return $result; +} +function mysql_join_install_target_providers_dependencies ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `dependencies`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`install_target`='; + } else { + $result .= ' ON `install_target_providers`.`install_target`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`depending_on`'; + } else { + $result .= '`dependencies`.`depending_on`'; + } + return $result; +} +function mysql_join_install_target_providers_install_targets ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `install_targets`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`install_target`='; + } else { + $result .= ' ON `install_target_providers`.`install_target`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`install_targets`.`id`'; + } + return $result; +} +function mysql_join_install_target_providers_versions ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `versions`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`version`='; + } else { + $result .= ' ON `install_target_providers`.`version`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`versions`.`id`'; + } + return $result; +} +function mysql_join_install_targets_dependencies ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `dependencies`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `install_targets`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`depending_on`'; + } else { + $result .= '`dependencies`.`depending_on`'; + } + return $result; +} +function mysql_join_install_targets_install_target_providers ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `install_target_providers`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `install_targets`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`install_target`'; + } else { + $result .= '`install_target_providers`.`install_target`'; + } + return $result; +} +function mysql_join_package_sources_build_assignments ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_assignments`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `package_sources`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`package_source`'; + } else { + $result .= '`build_assignments`.`package_source`'; + } + return $result; +} +function mysql_join_package_sources_repository_moves ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `repository_moves`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`upstream_package_repository`='; + } else { + $result .= ' ON `package_sources`.`upstream_package_repository`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`upstream_package_repository`'; + } else { + $result .= '`repository_moves`.`upstream_package_repository`'; + } + return $result; +} +function mysql_join_package_sources_toolchain_order ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `toolchain_order`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`pkgbase`='; + } else { + $result .= ' ON `package_sources`.`pkgbase`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`pkgbase`'; + } else { + $result .= '`toolchain_order`.`pkgbase`'; + } + return $result; +} +function mysql_join_package_sources_upstream_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `upstream_repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`upstream_package_repository`='; + } else { + $result .= ' ON `package_sources`.`upstream_package_repository`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`upstream_repositories`.`id`'; + } + return $result; +} +function mysql_join_persons_gpg_keys ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `gpg_keys`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `persons`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`owner`'; + } else { + $result .= '`gpg_keys`.`owner`'; + } + return $result; +} +function mysql_join_persons_ssh_keys ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `ssh_keys`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `persons`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`owner`'; + } else { + $result .= '`ssh_keys`.`owner`'; + } + return $result; +} +function mysql_join_repositories_architectures ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `architectures`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`architecture`='; + } else { + $result .= ' ON `repositories`.`architecture`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`architectures`.`id`'; + } + return $result; +} +function mysql_join_repositories_binary_packages_in_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `binary_packages_in_repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `repositories`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`repository`'; + } else { + $result .= '`binary_packages_in_repositories`.`repository`'; + } + return $result; +} +function mysql_join_repositories_repository_stabilities ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `repository_stabilities`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`stability`='; + } else { + $result .= ' ON `repositories`.`stability`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`repository_stabilities`.`id`'; + } + return $result; +} +function mysql_join_repository_moves_package_sources ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `package_sources`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`upstream_package_repository`='; + } else { + $result .= ' ON `repository_moves`.`upstream_package_repository`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`upstream_package_repository`'; + } else { + $result .= '`package_sources`.`upstream_package_repository`'; + } + return $result; +} +function mysql_join_repository_moves_upstream_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `upstream_repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`upstream_package_repository`='; + } else { + $result .= ' ON `repository_moves`.`upstream_package_repository`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`upstream_repositories`.`id`'; + } + return $result; +} +function mysql_join_repository_stabilities_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `repository_stabilities`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`stability`'; + } else { + $result .= '`repositories`.`stability`'; + } + return $result; +} +function mysql_join_ssh_keys_build_slaves ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_slaves`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `ssh_keys`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`ssh_key`'; + } else { + $result .= '`build_slaves`.`ssh_key`'; + } + return $result; +} +function mysql_join_ssh_keys_persons ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `persons`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`owner`='; + } else { + $result .= ' ON `ssh_keys`.`owner`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`persons`.`id`'; + } + return $result; +} +function mysql_join_ssh_log_build_slaves ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `build_slaves`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`build_slave`='; + } else { + $result .= ' ON `ssh_log`.`build_slave`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`build_slaves`.`id`'; + } + return $result; +} +function mysql_join_toolchain_order_package_sources ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `package_sources`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`pkgbase`='; + } else { + $result .= ' ON `toolchain_order`.`pkgbase`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`pkgbase`'; + } else { + $result .= '`package_sources`.`pkgbase`'; + } + return $result; +} +function mysql_join_upstream_repositories_git_repositories ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `git_repositories`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`git_repository`='; + } else { + $result .= ' ON `upstream_repositories`.`git_repository`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`id`'; + } else { + $result .= '`git_repositories`.`id`'; + } + return $result; +} +function mysql_join_upstream_repositories_package_sources ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `package_sources`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `upstream_repositories`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`upstream_package_repository`'; + } else { + $result .= '`package_sources`.`upstream_package_repository`'; + } + return $result; +} +function mysql_join_upstream_repositories_repository_moves ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `repository_moves`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `upstream_repositories`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`upstream_package_repository`'; + } else { + $result .= '`repository_moves`.`upstream_package_repository`'; + } + return $result; +} +function mysql_join_versions_dependencies ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `dependencies`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `versions`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`version`'; + } else { + $result .= '`dependencies`.`version`'; + } + return $result; +} +function mysql_join_versions_install_target_providers ($table_left="", $table_right="") { + $result = ""; + $result .= ' JOIN `install_target_providers`'; + if (!empty($table_right)) { + $result .= ' AS `'.$table_right.'`'; + } + if (!empty($table_left)) { + $result .= ' ON `'.$table_left.'`.`id`='; + } else { + $result .= ' ON `versions`.`id`='; + } + if (!empty($table_right)) { + $result .= '`'.$table_right.'`.`version`'; + } else { + $result .= '`install_target_providers`.`version`'; + } + return $result; +} diff --git a/lib/mysql.php b/lib/mysql.php new file mode 100644 index 0000000..19d0dae --- /dev/null +++ b/lib/mysql.php @@ -0,0 +1,90 @@ +<?php + +# do not include twice +if (isset($mysql)) + return; + +require_once "../init.php"; +include_once BASE . "/lib/http.php"; +include_once BASE . "/lib/mysql-joins.php"; + +$mysql = new mysqli("localhost", "webserver", "empty", "buildmaster"); +if ( $mysql -> connect_error ) { + die_500( "Connection failed: " . $mysql -> connect_error ); +} + +function print_important_trace_components($call) { + return substr($call['file'], strlen(BASE)+1) . '(' . $call['line'] . ')'; +} + +function mysql_log_duration_and_trace($start) { + $start = round((microtime(true) - $start) * 1000000); + $trace = debug_backtrace(); + array_shift($trace); + // silently fail if logfile is unavailable + if (($fp = fopen(BASE . '/log', 'a')) !== false) { + flock($fp, LOCK_EX); + fwrite($fp, + date('Y-m-d H:i:s') . " " . + $start . " " . + implode(' ', array_map('print_important_trace_components', $trace)) . " - " . + $trace[0]['args'][0] . "\n" + ); + flock($fp, LOCK_UN); + fclose($fp); + } +} + +function mysql_run_query($query) { + global $mysql; + $start = microtime(true); + if ( ! $result = $mysql -> query($query) ) + die_500( "Query failed: " . $mysql -> error ); + mysql_log_duration_and_trace($start); + return $result; +} + +function mysql_prepare_query($query) { + global $mysql; + $start = microtime(true); + if ( ! $result = $mysql -> prepare($query) ) + die_500( "Prepare failed: " . $mysql -> error ); + mysql_log_duration_and_trace($start); + return $result; +} + +function show_warning_on_offline_slave() { + $result = mysql_run_query("SHOW STATUS LIKE \"Slave_running\""); + if (($result -> num_rows == 0) || + ($result -> fetch_assoc() ["Value"] != "ON")) { + print "<div><font color=\"ff0000\">The replication slave is currently not running. The database might be outdated.</font></div>\n"; + } +} + +function mysql_url_encode($input) { + return + "REPLACE(" . $input . ",\"+\",\"%2B\")"; +} + +function mysql_query_package_version($table) { + return + "CONCAT(" . + "IF(" . + "`" .$table . "`.`epoch`=\"0\"," . + "\"\"," . + "CONCAT(" . + "`" . $table . "`.`epoch`," . + "\":\"" . + ")" . + ")," . + "`" . $table . "`.`pkgver`,\"-\"," . + "`" . $table . "`.`pkgrel`," . + "IF(`" . $table . "`.`sub_pkgrel_omitted`," . + "\"\"," . + "CONCAT(" . + "\".\"," . + "`" . $table . "`.`sub_pkgrel`" . + ")" . + ")" . + ")"; +} diff --git a/lib/style.php b/lib/style.php new file mode 100644 index 0000000..29659f6 --- /dev/null +++ b/lib/style.php @@ -0,0 +1,74 @@ +<?php + +if (function_exists("print_header")) + return; + +require_once "../init.php"; +require_once BASE . "/lib/mysql.php"; + +function print_header($title) { +?> +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8" /> + <title>Arch Linux 32 - <?php print $title; ?></title> + <link rel="stylesheet" type="text/css" href="/static/archweb.css" media="screen, projection" /> + <link rel="icon" type="image/x-icon" href="/static/favicon.ico" /> + <link rel="shortcut icon" type="image/x-icon" href="/static/favicon.ico" /> + <link rel="stylesheet" type="text/css" href="/static/flags/fam.47411010d402.css" media="screen, projection" /> + </head> + <body class=""> + <div id="archnavbar" class="anb-packages"> + <div id="archnavbarlogo"> + <h1><a href="/" title="Return to the main page">Arch Linux</a></h1> + </div> + <div id="archnavbarmenu"> + <ul id="archnavbarlist"> + <li id="anb-home"><a href="https://www.archlinux32.org/">Home</a></li> + <li id="anb-news"><a href="https://news.archlinux32.org/">News</a></li> + <li id="anb-packages"><a href="https://packages.archlinux32.org/">Packages</a></li> + <li id="anb-forums"><a href="https://bbs.archlinux32.org/">Forums</a></li> + <li id="anb-bugs"><a href="https://bugs.archlinux32.org/" title="Report and track bugs">Bugs</a></li> + <li id="anb-mailing-list"><a href="https://lists.archlinux.org/listinfo/arch-ports">Mailing List</a></li> + <li id="anb-download"><a href="https://www.archlinux32.org/download/" title="Get Arch Linux">Download</a></li> + <li id="anb-arch-linux-official"><a href="https://www.archlinux.org/">Arch Linux Official</a></li> + </ul> + </div> + </div> + <div id="content"> +<?php + show_warning_on_offline_slave(); +} + +function print_footer() { +?> + <div id="footer"> + <p> + Copyright © 2002-2018 <a href="mailto:jvinet@zeroflux.org" title="Contact Judd Vinet">Judd Vinet</a> and <a href="mailto:aaron@archlinux.org" title="Contact Aaron Griffin">Aaron Griffin</a>. + Copyright © 2018 <a href="mailto:arch@eckner.net" title="Contact Erich Eckner">Erich Eckner</a>. + </p> + <p> + The Arch Linux name and logo are recognized <a href="https://wiki.archlinux.org/index.php/DeveloperWiki:TrademarkPolicy" title="Arch Linux Trademark Policy">trademarks</a>. Some rights reserved. + </p> + <p> + The registered trademark Linux® is used pursuant to a sublicense from LMI, the exclusive licensee of Linus Torvalds, owner of the mark on a world-wide basis. + </p> + </div> + </div> + <script type="application/ld+json"> + { + "@context": "http://schema.org", + "@type": "WebSite", + "url": "/", + "potentialAction": { + "@type": "SearchAction", + "target": "/?q={search_term}", + "query-input": "required name=search_term" + } + } + </script> + </body> +</html> +<?php +} |