Annotation of FreeBSD/tinderbox/webui/core/TinderboxDS.php, revision 1.1
1.1 ! as 1: <?php
! 2: #-
! 3: # Copyright (c) 2004-2005 FreeBSD GNOME Team <freebsd-gnome@FreeBSD.org>
! 4: # All rights reserved.
! 5: #
! 6: # Redistribution and use in source and binary forms, with or without
! 7: # modification, are permitted provided that the following conditions
! 8: # are met:
! 9: # 1. Redistributions of source code must retain the above copyright
! 10: # notice, this list of conditions and the following disclaimer.
! 11: # 2. Redistributions in binary form must reproduce the above copyright
! 12: # notice, this list of conditions and the following disclaimer in the
! 13: # documentation and/or other materials provided with the distribution.
! 14: #
! 15: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
! 16: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 17: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 18: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
! 19: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 20: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 21: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 22: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 23: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 24: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 25: # SUCH DAMAGE.
! 26: #
! 27: # $MCom: portstools/tinderbox/webui/core/TinderboxDS.php,v 1.36 2007/10/13 02:28:47 ade Exp $
! 28: #
! 29:
! 30: require_once 'DB.php';
! 31: require_once 'Build.php';
! 32: require_once 'BuildPortsQueue.php';
! 33: require_once 'Config.php';
! 34: require_once 'Jail.php';
! 35: require_once 'Port.php';
! 36: require_once 'PortsTree.php';
! 37: require_once 'PortFailReason.php';
! 38: require_once 'User.php';
! 39: require_once 'inc_ds.php';
! 40: require_once 'inc_tinderbox.php';
! 41:
! 42: $objectMap = array(
! 43: "Build" => "builds",
! 44: "BuildPortsQueue" => "build_ports_queue",
! 45: "Config" => "config",
! 46: "Jail" => "jails",
! 47: "Port" => "ports",
! 48: "PortsTree" => "ports_trees",
! 49: "PortFailReason" => "port_fail_reasons",
! 50: "User" => "users",
! 51: );
! 52:
! 53: class TinderboxDS {
! 54: var $db;
! 55: var $error;
! 56: var $packageSuffixCache; /* in use by getPackageSuffix() */
! 57:
! 58: function TinderboxDS() {
! 59: global $DB_HOST, $DB_DRIVER, $DB_NAME, $DB_USER, $DB_PASS;
! 60:
! 61: # XXX: backwards compatibility
! 62: if ($DB_DRIVER == "")
! 63: $DB_DRIVER = "mysql";
! 64:
! 65: $dsn = "$DB_DRIVER://$DB_USER:$DB_PASS@$DB_HOST/$DB_NAME";
! 66:
! 67: $this->db = DB::connect($dsn);
! 68:
! 69: if (DB::isError($this->db)) {
! 70: die ("Tinderbox DS: Unable to initialize datastore: " . $this->db->getMessage() . "\n");
! 71: }
! 72:
! 73: $this->db->setFetchMode(DB_FETCHMODE_ASSOC);
! 74: $this->db->setOption('persistent', true);
! 75: }
! 76:
! 77: function start_transaction() {
! 78: $this->db->autoCommit( false );
! 79: }
! 80:
! 81: function commit_transaction() {
! 82: $this->db->commit();
! 83: $this->db->autoCommit( true );
! 84: }
! 85:
! 86: function rollback_transaction() {
! 87: $this->db->rollback();
! 88: $this->db->autoCommit( true );
! 89: }
! 90:
! 91: function getAllMaintainers() {
! 92: $query = "SELECT DISTINCT LOWER(port_maintainer) AS port_maintainer FROM ports where port_maintainer IS NOT NULL ORDER BY LOWER(port_maintainer)";
! 93: $rc = $this->_doQueryHashRef($query, $results, array());
! 94:
! 95: if (!$rc) {
! 96: return array();
! 97: }
! 98:
! 99: foreach($results as $result)
! 100: $data[]=$result['port_maintainer'];
! 101:
! 102: return $data;
! 103: }
! 104:
! 105: function getAllPortsByPortID($portid) {
! 106: $query = "SELECT p.*,
! 107: bp.build_id,
! 108: bp.last_built,
! 109: bp.last_status,
! 110: bp.last_successful_built,
! 111: bp.last_failed_dependency,
! 112: bp.last_run_duration,
! 113: bp.last_built_version,
! 114: CASE bp.last_fail_reason
! 115: WHEN '__nofail__' THEN ''
! 116: ELSE bp.last_fail_reason
! 117: END
! 118: AS last_fail_reason
! 119: FROM ports p,
! 120: build_ports bp
! 121: WHERE p.port_id = bp.port_id
! 122: AND bp.port_id=$portid";
! 123:
! 124: $rc = $this->_doQueryHashRef($query, $results, array());
! 125:
! 126: if (!$rc) {
! 127: return null;
! 128: }
! 129:
! 130: $ports = $this->_newFromArray("Port", $results);
! 131:
! 132: return $ports;
! 133: }
! 134:
! 135:
! 136: function addUser($user) {
! 137: $query = "INSERT INTO users
! 138: (user_name,user_email,user_password,user_www_enabled)
! 139: VALUES
! 140: (?,?,?,?)";
! 141:
! 142: $rc = $this->_doQuery($query, array($user->getName(),$user->getEmail(),$user->getPassword(),$user->getWwwEnabled()),$res);
! 143:
! 144: if (!$rc) {
! 145: return false;
! 146: }
! 147:
! 148: return true;
! 149: }
! 150:
! 151: function deleteUser($user) {
! 152: if( !$user->getId() || $this->deleteUserPermissions($user,'') ) {
! 153: if ($user->getId()) {
! 154: $this->deleteBuildPortsQueueByUserId($user);
! 155: }
! 156: $query = "DELETE FROM users
! 157: WHERE user_name=?";
! 158:
! 159: $rc = $this->_doQuery($query, array($user->getName()),$res);
! 160:
! 161: if (!$rc) {
! 162: return false;
! 163: }
! 164:
! 165: return true;
! 166: }
! 167: return false;
! 168: }
! 169:
! 170: function updateUser($user) {
! 171: $query = "UPDATE users
! 172: SET user_name=?,user_email=?,user_password=?,user_www_enabled=?
! 173: WHERE user_id=?";
! 174:
! 175: $rc = $this->_doQuery($query, array($user->getName(),$user->getEmail(),$user->getPassword(),$user->getWwwEnabled(),$user->getId()),$res);
! 176:
! 177: if (!$rc) {
! 178: return false;
! 179: }
! 180:
! 181: return true;
! 182: }
! 183:
! 184: function getUserByLogin($username,$password) {
! 185: $hashPass = md5($password);
! 186: $query = "SELECT user_id,user_name,user_email,user_password,user_www_enabled FROM users WHERE user_name=? AND user_password=?";
! 187: $rc = $this->_doQueryHashRef($query, $results, array($username,$hashPass));
! 188:
! 189: if (!$rc) {
! 190: return null;
! 191: }
! 192:
! 193: $user = $this->_newFromArray("User", $results);
! 194:
! 195: return $user[0];
! 196: }
! 197:
! 198: function getUserPermissions($user_id,$object_type,$object_id) {
! 199:
! 200: $query = "
! 201: SELECT
! 202: CASE user_permission
! 203: WHEN 1 THEN 'IS_WWW_ADMIN'
! 204: WHEN 2 THEN 'PERM_ADD_QUEUE'
! 205: WHEN 3 THEN 'PERM_MODIFY_OWN_QUEUE'
! 206: WHEN 4 THEN 'PERM_DELETE_OWN_QUEUE'
! 207: WHEN 5 THEN 'PERM_PRIO_LOWER_5'
! 208: WHEN 6 THEN 'PERM_MODIFY_OTHER_QUEUE'
! 209: WHEN 7 THEN 'PERM_DELETE_OTHER_QUEUE'
! 210: ELSE 'PERM_UNKNOWN'
! 211: END
! 212: AS user_permission
! 213: FROM user_permissions
! 214: WHERE user_id=?
! 215: AND user_permission_object_type=?
! 216: AND user_permission_object_id=?";
! 217:
! 218: $rc = $this->_doQueryHashRef($query, $results, array($user_id,$object_type,$object_id));
! 219:
! 220: if (!$rc) {
! 221: return null;
! 222: }
! 223:
! 224: return $results;
! 225: }
! 226:
! 227: function deleteUserPermissions($user, $object_type) {
! 228:
! 229: $query = "
! 230: DELETE FROM user_permissions
! 231: WHERE user_id=?";
! 232:
! 233: if( $object_type )
! 234: $query .= " AND user_permission_object_type='$object_type'";
! 235:
! 236: $rc = $this->_doQuery($query, array($user->getId()), $res);
! 237:
! 238: if (!$rc) {
! 239: return false;
! 240: }
! 241:
! 242: return true;
! 243: }
! 244:
! 245: function addUserPermission($user_id,$object_type,$object_id,$permission) {
! 246:
! 247: switch( $permission ) {
! 248: // case 'IS_WWW_ADMIN': $permission = 1; break; /* only configureable via shell */
! 249: case 'PERM_ADD_QUEUE': $permission = 2; break;
! 250: case 'PERM_MODIFY_OWN_QUEUE': $permission = 3; break;
! 251: case 'PERM_DELETE_OWN_QUEUE': $permission = 4; break;
! 252: case 'PERM_PRIO_LOWER_5': $permission = 5; break;
! 253: case 'PERM_MODIFY_OTHER_QUEUE': $permission = 6; break;
! 254: case 'PERM_DELETE_OTHER_QUEUE': $permission = 7; break;
! 255: default: return false;
! 256: }
! 257:
! 258: $query = "
! 259: INSERT INTO user_permissions
! 260: (user_id,user_permission_object_type,user_permission_object_id,user_permission)
! 261: VALUES
! 262: (?,?,?,?)";
! 263:
! 264: $rc = $this->_doQuery($query, array($user_id,$object_type,$object_id,$permission), $res);
! 265:
! 266: if (!$rc) {
! 267: return false;
! 268: }
! 269:
! 270: return true;
! 271: }
! 272:
! 273: function getBuildPortsQueueEntries($build_id) {
! 274: $query = "SELECT build_ports_queue.*, builds.build_name AS build_name, users.user_name AS user_name
! 275: FROM build_ports_queue, builds, users
! 276: WHERE build_ports_queue.build_id=?
! 277: AND builds.build_id = build_ports_queue.build_id
! 278: AND users.user_id = build_ports_queue.user_id
! 279: ORDER BY priority ASC, build_ports_queue_id ASC";
! 280: $rc = $this->_doQueryHashRef($query, $results, array($build_id));
! 281:
! 282: if (!$rc) {
! 283: return null;
! 284: }
! 285:
! 286: $build_ports_queue_entries = $this->_newFromArray("BuildPortsQueue", $results);
! 287:
! 288: return $build_ports_queue_entries;
! 289: }
! 290:
! 291: function deleteBuildPortsQueueEntry($entry_id) {
! 292: $query = "DELETE FROM build_ports_queue
! 293: WHERE build_ports_queue_id=?";
! 294:
! 295: $rc = $this->_doQuery($query, $entry_id, $res);
! 296:
! 297: if (!$rc) {
! 298: return false;
! 299: }
! 300:
! 301: return true;
! 302: }
! 303:
! 304: function deleteBuildPortsQueueByUserId($user) {
! 305: $query = "DELETE FROM build_ports_queue
! 306: WHERE user_id=?";
! 307:
! 308: $rc = $this->_doQuery($query, $user->getId(), $res);
! 309:
! 310: if (!$rc) {
! 311: return false;
! 312: }
! 313:
! 314: return true;
! 315: }
! 316:
! 317: function createBuildPortsQueueEntry($build_id,$priority,$port_directory,$user_id,$email_on_completion) {
! 318: switch( $email_on_completion ) {
! 319: case '1': $email_on_completion = 1; break;
! 320: default: $email_on_completion = 0; break;
! 321: }
! 322:
! 323: $entries[] = array('build_id' => $build_id,
! 324: 'priority' => $priority,
! 325: 'port_directory' => $port_directory,
! 326: 'user_id' => $user_id,
! 327: 'enqueue_date' => date("Y-m-d H:i:s", time()),
! 328: 'email_on_completion' => $email_on_completion,
! 329: 'status' => 'ENQUEUED');
! 330:
! 331: $results = $this->_newFromArray("BuildPortsQueue",$entries);
! 332:
! 333: return $results[0];
! 334: }
! 335:
! 336: function updateBuildPortsQueueEntry($entry) {
! 337:
! 338: $query = "UPDATE build_ports_queue
! 339: SET build_id=?, priority=?, email_on_completion=?, status=?
! 340: WHERE build_ports_queue_id=?";
! 341:
! 342: $rc = $this->_doQuery($query, array($entry->getBuildId(),$entry->getPriority(),$entry->getEmailOnCompletion(),$entry->getStatus(),$entry->getId()), $res);
! 343:
! 344: if (!$rc) {
! 345: return false;
! 346: }
! 347:
! 348: return true;
! 349: }
! 350:
! 351: function addBuildPortsQueueEntry($entry) {
! 352: $query = "INSERT INTO build_ports_queue
! 353: (enqueue_date,build_id,priority,port_directory,user_id,email_on_completion,status)
! 354: VALUES
! 355: (?,?,?,?,?,?,?)";
! 356:
! 357: $rc = $this->_doQuery($query, array($entry->getEnqueueDate(),$entry->getBuildId(),$entry->getPriority(),$entry->getPortDirectory(),$entry->getUserId(),$entry->getEmailOnCompletion(),$entry->getStatus()), $res);
! 358:
! 359: if (!$rc) {
! 360: return false;
! 361: }
! 362:
! 363: return true;
! 364: }
! 365:
! 366: function getBuildPortsQueueEntryById($id) {
! 367: $results = $this->getBuildPortsQueue(array( 'build_ports_queue_id' => $id ));
! 368:
! 369: if (is_null($results)) {
! 370: return null;
! 371: }
! 372:
! 373: return $results[0];
! 374: }
! 375:
! 376: function getPortsForBuild($build, $sortby = 'port_directory') {
! 377: $sortbytable = "bp";
! 378: if ($sortby == "") $sortby = "port_directory";
! 379: if ($sortby == "port_directory") $sortbytable = "p";
! 380: if ($sortby == "port_maintainer") $sortbytable = "p";
! 381: $query = "SELECT p.*,
! 382: bp.last_built,
! 383: bp.last_status,
! 384: bp.last_successful_built,
! 385: bp.last_built_version,
! 386: bp.last_failed_dependency,
! 387: bp.last_run_duration,
! 388: CASE bp.last_fail_reason
! 389: WHEN '__nofail__' THEN ''
! 390: ELSE bp.last_fail_reason
! 391: END
! 392: AS last_fail_reason
! 393: FROM ports p,
! 394: build_ports bp
! 395: WHERE p.port_id = bp.port_id
! 396: AND bp.build_id=?
! 397: ORDER BY $sortbytable.$sortby";
! 398:
! 399: $rc = $this->_doQueryHashRef($query, $results, $build->getId());
! 400:
! 401: if (!$rc) {
! 402: return null;
! 403: }
! 404:
! 405: $ports = $this->_newFromArray("Port", $results);
! 406:
! 407: return $ports;
! 408: }
! 409:
! 410: function getLatestPorts($build_id,$limit="") {
! 411: $query = "SELECT p.*,
! 412: bp.build_id,
! 413: bp.last_built,
! 414: bp.last_status,
! 415: bp.last_successful_built,
! 416: bp.last_built_version,
! 417: bp.last_failed_dependency,
! 418: bp.last_run_duration,
! 419: CASE bp.last_fail_reason
! 420: WHEN '__nofail__' THEN ''
! 421: ELSE bp.last_fail_reason
! 422: END
! 423: AS last_fail_reason
! 424: FROM ports p,
! 425: build_ports bp
! 426: WHERE p.port_id = bp.port_id
! 427: AND bp.last_built IS NOT NULL ";
! 428: if($build_id)
! 429: $query .= "AND bp.build_id=$build_id ";
! 430: $query .= " ORDER BY bp.last_built DESC ";
! 431: if($limit)
! 432: $query .= " LIMIT $limit";
! 433:
! 434: $rc = $this->_doQueryHashRef($query, $results, array());
! 435:
! 436: if (!$rc) {
! 437: return null;
! 438: }
! 439:
! 440: $ports = $this->_newFromArray("Port", $results);
! 441:
! 442: return $ports;
! 443: }
! 444:
! 445: function getBuildPorts($port_id,$build_id) {
! 446: $query = "SELECT p.*,
! 447: bp.last_built,
! 448: bp.last_status,
! 449: bp.last_successful_built,
! 450: bp.last_failed_dependency,
! 451: bp.last_run_duration,
! 452: CASE bp.last_fail_reason
! 453: WHEN '__nofail__' THEN ''
! 454: ELSE bp.last_fail_reason
! 455: END
! 456: AS last_fail_reason
! 457: FROM ports p,
! 458: build_ports bp
! 459: WHERE p.port_id = bp.port_id
! 460: AND bp.build_id=?
! 461: AND bp.port_id=?";
! 462:
! 463: $rc = $this->_doQueryHashRef($query, $results, array($build_id, $port_id));
! 464: if (!$rc) return null;
! 465:
! 466: $ports = $this->_newFromArray("Port", $results);
! 467:
! 468: return $ports[0];
! 469: }
! 470:
! 471:
! 472: function getPortsByStatus($build_id,$maintainer,$status,$notstatus) {
! 473: $query = "SELECT p.*,
! 474: bp.build_id,
! 475: bp.last_built,
! 476: bp.last_status,
! 477: bp.last_successful_built,
! 478: bp.last_built_version,
! 479: bp.last_failed_dependency,
! 480: bp.last_run_duration,
! 481: CASE bp.last_fail_reason
! 482: WHEN '__nofail__' THEN ''
! 483: ELSE bp.last_fail_reason
! 484: END
! 485: AS last_fail_reason
! 486: FROM ports p,
! 487: build_ports bp
! 488: WHERE p.port_id = bp.port_id ";
! 489:
! 490: if($build_id)
! 491: $query .= "AND bp.build_id=$build_id ";
! 492: if($status<>'')
! 493: $query .= "AND bp.last_status='$status' ";
! 494: if($notstatus<>'')
! 495: $query .= "AND bp.last_status<>'$notstatus' AND bp.last_status<>'UNKNOWN'";
! 496: if($maintainer)
! 497: $query .= "AND p.port_maintainer='$maintainer'";
! 498: $query .= " ORDER BY bp.last_built DESC ";
! 499:
! 500: $rc = $this->_doQueryHashRef($query, $results, array());
! 501:
! 502: if (!$rc) {
! 503: return null;
! 504: }
! 505:
! 506: $ports = $this->_newFromArray("Port", $results);
! 507:
! 508: return $ports;
! 509: }
! 510:
! 511: function getBuildStatsWithStatus($build_id) {
! 512: $query = 'SELECT last_status,COUNT(*) AS c FROM build_ports WHERE build_id = ? GROUP BY last_status';
! 513: $rc = $this->_doQueryHashRef($query, $results, $build_id);
! 514: if (!$rc) return null;
! 515: return $results;
! 516: }
! 517:
! 518:
! 519: function getBuildStats($build_id) {
! 520: $query = 'SELECT COUNT(*) AS fails FROM build_ports WHERE last_status = \'FAIL\' AND build_id = ?';
! 521: $rc = $this->_doQueryHashRef($query, $results, $build_id);
! 522: if (!$rc) return null;
! 523: return $results[0];
! 524: }
! 525:
! 526: function getPortById($id) {
! 527: $results = $this->getPorts(array( 'port_id' => $id ));
! 528:
! 529: if (is_null($results)) {
! 530: return null;
! 531: }
! 532:
! 533: return $results[0];
! 534: }
! 535:
! 536: function getPortByDirectory($dir) {
! 537: $results = $this->getPorts(array( 'port_directory' => $dir ));
! 538:
! 539: if (is_null($results)) {
! 540: return null;
! 541: }
! 542:
! 543: return $results[0];
! 544: }
! 545:
! 546: function getCurrentPortForBuild($build_id) {
! 547: $query = 'SELECT port_id AS id FROM build_ports WHERE build_id = ? AND currently_building = \'1\'';
! 548: $rc = $this->_doQueryHashRef($query, $results, array($build_id));
! 549: if (!$rc) return null;
! 550: $port = $this->getPortById($results[0]['id']);
! 551:
! 552: return $port;
! 553: }
! 554:
! 555: function getObjects($type, $params = array()) {
! 556: global $objectMap;
! 557:
! 558: if (!isset($objectMap[$type])) {
! 559: die("Unknown object type, $type\n");
! 560: }
! 561:
! 562: $table = $objectMap[$type];
! 563: $condition = "";
! 564:
! 565: $values = array();
! 566: $conds = array();
! 567: foreach ($params as $field => $param) {
! 568: # Each parameter makes up and OR portion of a query. Within
! 569: # each parameter can be a hash reference that make up the AND
! 570: # portion of the query.
! 571: if (is_array($param)) {
! 572: $ands = array();
! 573: foreach ($param as $andcond => $value) {
! 574: array_push($ands, "$andcond=?");
! 575: array_push($values, $value);
! 576: }
! 577: array_push($conds, "(" . (implode(" AND ", $ands)) . ")");
! 578: } else {
! 579: array_push($conds, "(" . $field . "=?)");
! 580: array_push($values, $param);
! 581: }
! 582: }
! 583:
! 584: $condition = implode(" OR ", $conds);
! 585:
! 586: if ($condition != "") {
! 587: $query = "SELECT * FROM $table WHERE $condition";
! 588: }
! 589: else {
! 590: $query = "SELECT * FROM $table";
! 591: }
! 592:
! 593: $results = array();
! 594: $rc = $this->_doQueryHashRef($query, $results, $values);
! 595:
! 596: if (!$rc) {
! 597: return null;
! 598: }
! 599:
! 600: return $this->_newFromArray($type, $results);
! 601: }
! 602:
! 603: function getBuildByName($name) {
! 604: $results = $this->getBuilds(array( 'build_name' => $name ));
! 605:
! 606: if (is_null($results)) {
! 607: return null;
! 608: }
! 609:
! 610: return $results[0];
! 611: }
! 612:
! 613: function getBuildById($id) {
! 614: $results = $this->getBuilds(array( 'build_id' => $id ));
! 615:
! 616: if (is_null($results)) {
! 617: return null;
! 618: }
! 619:
! 620: return $results[0];
! 621: }
! 622:
! 623: function getJailById($id) {
! 624: $results = $this->getJails(array( 'jail_id' => $id ));
! 625:
! 626: if (is_null($results)) {
! 627: return null;
! 628: }
! 629:
! 630: return $results[0];
! 631: }
! 632:
! 633: function getPortsTreeForBuild($build) {
! 634: $portstree = $this->getPortsTreeById($build->getPortsTreeId());
! 635:
! 636: return $portstree;
! 637: }
! 638:
! 639: function getPortsTreeByName($name) {
! 640: $results = $this->getPortsTrees(array( 'ports_tree_name' => $name ));
! 641: if (is_null($results)) {
! 642: return null;
! 643: }
! 644:
! 645: return $results[0];
! 646: }
! 647:
! 648: function getPortsTreeById($id) {
! 649: $results = $this->getPortsTrees(array( 'ports_tree_id' => $id ));
! 650:
! 651: if (is_null($results)) {
! 652: return null;
! 653: }
! 654:
! 655: return $results[0];
! 656: }
! 657:
! 658: function getUserById($id) {
! 659: $results = $this->getUsers(array( 'user_id' => $id ));
! 660:
! 661: if (is_null($results)) {
! 662: return null;
! 663: }
! 664:
! 665: return $results[0];
! 666: }
! 667:
! 668: function getUserByName($name) {
! 669: $results = $this->getUsers(array( 'user_name' => $name ));
! 670:
! 671: if (is_null($results)) {
! 672: return null;
! 673: }
! 674:
! 675: return $results[0];
! 676: }
! 677:
! 678: function getConfig($params = array()) {
! 679: return $this->getObjects("Config", $params);
! 680: }
! 681:
! 682: function getBuildPortsQueue($params = array()) {
! 683: return $this->getObjects("BuildPortsQueue", $params);
! 684: }
! 685:
! 686: function getBuilds($params = array()) {
! 687: return $this->getObjects("Build", $params);
! 688: }
! 689:
! 690: function getPorts($params = array()) {
! 691: return $this->getObjects("Port", $params);
! 692: }
! 693:
! 694: function getJails($params = array()) {
! 695: return $this->getObjects("Jail", $params);
! 696: }
! 697:
! 698: function getPortFailReasons($params = array()) {
! 699: return $this->getObjects("PortFailReason", $params);
! 700: }
! 701:
! 702: function getPortsTrees($params = array()) {
! 703: return $this->getObjects("PortsTree", $params);
! 704: }
! 705:
! 706: function getUsers($params = array()) {
! 707: return $this->getObjects("User", $params);
! 708: }
! 709:
! 710: function getAllConfig() {
! 711: $config = $this->getConfig();
! 712:
! 713: return $config;
! 714: }
! 715:
! 716: function getAllBuilds() {
! 717: $builds = $this->getBuilds();
! 718:
! 719: return $builds;
! 720: }
! 721:
! 722: function getAllJails() {
! 723: $jails = $this->getJails();
! 724:
! 725: return $jails;
! 726: }
! 727:
! 728: function getAllPortFailReasons() {
! 729: $results = $this->getPortFailReasons();
! 730:
! 731: return $results;
! 732: }
! 733:
! 734: function getAllPortsTrees() {
! 735: $ports_trees = $this->getPortsTrees();
! 736:
! 737: return $ports_trees;
! 738: }
! 739:
! 740: function getAllUsers() {
! 741: $users = $this->getUsers();
! 742:
! 743: return $users;
! 744: }
! 745:
! 746: function addError($error) {
! 747: return $this->error[] = $error;
! 748: }
! 749:
! 750: function getErrors() {
! 751: return $this->error;
! 752: }
! 753:
! 754: function _doQueryNumRows($query, $params = array()) {
! 755: $rows = 0;
! 756: $rc = $this->_doQuery($query, $params, $res);
! 757:
! 758: if (!$rc) {
! 759: return -1;
! 760: }
! 761:
! 762: if ($res->numRows() > -1) {
! 763: $rows = $res->numRows();
! 764: }
! 765: else {
! 766: while($res->fetchRow()) {
! 767: $rows++;
! 768: }
! 769: }
! 770:
! 771: $res->free();
! 772:
! 773: return $rows;
! 774: }
! 775:
! 776: function _doQueryHashRef($query, &$results, $params = array()) {
! 777: $rc = $this->_doQuery($query, $params, $res);
! 778:
! 779: if (!$rc) {
! 780: $results = null;
! 781: return 0;
! 782: }
! 783:
! 784: $results = array();
! 785: while ($row = $res->fetchRow()) {
! 786: array_push($results, $row);
! 787: }
! 788:
! 789: $res->free();
! 790:
! 791: return 1;
! 792: }
! 793:
! 794: function _doQuery($query, $params, &$res) {
! 795: $sth = $this->db->prepare($query);
! 796:
! 797: if (DB::isError($this->db)) {
! 798: $this->addError($this->db->getMessage());
! 799: return 0;
! 800: }
! 801:
! 802: if (count($params)) {
! 803: $_res = $this->db->execute($sth, $params);
! 804: }
! 805: else {
! 806: $_res = $this->db->execute($sth);
! 807: }
! 808:
! 809: if (DB::isError($_res)) {
! 810: $this->addError($_res->getMessage());
! 811: return 0;
! 812: }
! 813:
! 814: if (!is_null($_res)) {
! 815: $res = $_res;
! 816: }
! 817: else {
! 818: $res->free();
! 819: }
! 820:
! 821: return 1;
! 822: }
! 823:
! 824: function _newFromArray($type, $arr) {
! 825: $objects = array();
! 826:
! 827: foreach ($arr as $item) {
! 828: eval('$obj = new $type($item);');
! 829: if (!is_a($obj, $type)) {
! 830: return null;
! 831: }
! 832: array_push($objects, $obj);
! 833: }
! 834:
! 835: return $objects;
! 836: }
! 837:
! 838: function destroy() {
! 839: $this->db->disconnect();
! 840: $this->error = null;
! 841: }
! 842:
! 843: function getPackageSuffix($jail_id) {
! 844: if (empty($jail_id)) return "";
! 845: /* Use caching to avoid a lot of SQL queries */
! 846: if ( isset($this->packageSuffixCache[$jail_id])) {
! 847: return $this->packageSuffixCache[$jail_id];
! 848: } else {
! 849: $jail = $this->getJailById($jail_id);
! 850: if (substr($jail->getName(), 0, 1) <= "4") {
! 851: $this->packageSuffixCache[$jail_id] = ".tgz";
! 852: return ".tgz";
! 853: } else {
! 854: $this->packageSuffixCache[$jail_id] = ".tbz";
! 855: return ".tbz";
! 856: }
! 857:
! 858: }
! 859: }
! 860: }
! 861: ?>