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