1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
|
<?php
/**
* @version $Header$
* @package install
*/
namespace Bitweaver\Install;
use Bitweaver\BitSystem;
use Bitweaver\BitDb;
use Bitweaver\KernelTools;
/**
* @package install
*/
class BitInstaller extends BitSystem {
/**
* mPackageUpgrades
*
* @var array
* @access public
*/
public $mPackageUpgrades = [];
/**
* mRequirements
*
* @var array
* @access public
*/
public $mRequirements = [];
public $mPrefs;
/**
* Initiolize BitInstaller
* @access public
*/
public function __construct() {
parent::__construct();
$this->getWebServerUid();
}
/**
* loadAllUpgradeFiles load upgrade files from all packages that are installed
*
* @access public
* @return void
*/
public function loadAllUpgradeFiles() {
foreach( array_keys( $this->mPackages ) as $pkg ) {
$this->loadUpgradeFiles( $pkg );
}
}
/**
* Minimal login just for install in case users tables have been modified
*
* @access public
* @return boolean
*/
public function login( $pLogin, $pPassword, $pChallenge=NULL, $pResponse=NULL ) {
global $gBitUser;
$isvalid = false;
$loginCol = strpos( $pLogin, '@' ) ? 'email' : 'login';
if( $gBitUser->validate( $pLogin, $pPassword, $pChallenge, $pResponse ) ) {
$userInfo = $gBitUser->getUserInfo( [ $loginCol => $pLogin ] );
if( $userInfo['user_id'] != ANONYMOUS_USER_ID ) {
// User is valid and not due to change pass..
$gBitUser->mUserId = $userInfo['user_id'];
$gBitUser->mInfo = $userInfo;
$gBitUser->loadPermissions( TRUE );
$sessionId = session_id();
$gBitUser->sendSessionCookie( $sessionId );
$gBitUser->updateSession( $sessionId );
}
}
return $gBitUser->isAdmin();
}
/**
* loadUpgradeFiles This will load all files in the dir <pckage>/admin/upgrades/<version>.php with a version greater than the one installed
*
* @param string $pPackage
* @access public
* @return void
*/
public function loadUpgradeFiles( $pPackage ) {
if( !empty( $pPackage )) {
$dir = constant( strtoupper( $pPackage )."_PKG_PATH" )."admin/upgrades/";
if( $this->isPackageActive( $pPackage ) && is_dir( $dir ) && $upDir = opendir( $dir )) {
while( FALSE !== ( $file = readdir( $upDir ))) {
if( is_file( $dir.$file )) {
$upVersion = str_replace( ".php", "", $file );
// we only want to load files of versions that are greater than is installed
if( $this->validateVersion( $upVersion ) && version_compare( $this->getVersion( $pPackage ), $upVersion, '<' )) {
include_once( $dir.$file );
}
}
}
}
}
}
/**
* registerPackageUpgrade
*
* @param array $pParams Hash of information about upgrade
* @param string $pParams[package] Name of package that is upgrading
* @param string $pParams[version] Version of this upgrade
* @param string $pParams[description] Description of what the upgrade does
* @param string $pParams[post_upgrade] Textual note of stuff that needs to be observed after the upgrade
* @param array $pUpgradeHash Hash of update rules. See existing upgrades on how this works.
* @access public
* @return void
*/
public function registerPackageUpgrade( $pParams, $pUpgradeHash = [] ) {
if( $this->verifyPackageUpgrade( $pParams )) {
$this->registerPackageVersion( $pParams['package'], $pParams['version'] );
$this->mPackageUpgrades[$pParams['package']][$pParams['version']] = $pParams;
$this->mPackageUpgrades[$pParams['package']][$pParams['version']]['upgrade'] = $pUpgradeHash;
// sort everything for a nice display
ksort( $this->mPackageUpgrades );
uksort( $this->mPackageUpgrades[$pParams['package']], 'version_compare' );
}
}
/**
* verifyPackageUpgrade
*
* @param array $pParams Hash of information about upgrade
* @param string $pParams[package] Name of package that is upgrading
* @param string $pParams[version] Version of this upgrade
* @param string $pParams[description] Description of what the upgrade does
* @param string $pParams[post_upgrade] Textual note of stuff that needs to be observed after the upgrade
* @access public
* @return boolean TRUE on success, FALSE on failure - mErrors will contain reason for failure
*/
public function verifyPackageUpgrade( &$pParams ) {
if( empty( $pParams['package'] )) {
$this->mErrors['package'] = "Please provide a valid package name.";
} else {
$pParams['package'] = strtolower( $pParams['package'] );
}
if( empty( $pParams['version'] ) || !$this->validateVersion( $pParams['version'] )) {
$this->mErrors['version'] = "Please provide a valid version number.";
} elseif( empty( $this->mErrors ) && !empty( $this->mPackageUpgrades[$pParams['package']][$pParams['version']] )) {
$this->mErrors['version'] = "Please make sure you use a unique version number to register your new database changes.";
}
if( empty( $pParams['description'] )) {
$this->mErrors['description'] = "Please add a brief description of what this upgrade is all about.";
}
// since this should only show up when devs are working, we'll simply display the output:
if( !empty( $this->mErrors )) {
\Bitweaver\vd( $this->mErrors );
\Bitweaver\bt();
}
return( count( $this->mErrors ) == 0 );
}
/**
* registerUpgrade
*
* @param string $pPackage
* @param array $pUpgradeHash
* @access public
* @return void
*/
public function registerUpgrade( $pPackage, $pUpgradeHash ) {
$pPackage = strtolower( $pPackage ); // lower case for uniformity
if( !empty( $pUpgradeHash ) ) {
$this->mUpgrades[$pPackage] = $pUpgradeHash;
}
}
/**
* display
*
* @param string $pTemplate
* @param string $pBrowserTitle
* @access public
* @return void
*/
public function in_display( $pPackage, $pTemplate ) {
header( 'Content-Type: text/html; charset=utf-8' );
if( ini_get( 'safe_mode' ) && ini_get( 'safe_mode_gid' )) {
umask( 0007 );
}
// force the session to close *before* displaying. Why? Note this very important comment from http://us4.php.net/exec
session_write_close();
if( !empty( $pPackage ) ) {
$this->setBrowserTitle( $pPackage );
}
global $gBitSmarty;
$gBitSmarty->verifyCompileDir();
$gBitSmarty->display( $pTemplate );
}
/**
* isInstalled
*
* @access public
* @return boolean TRUE on success, FALSE on failure - mErrors will contain reason for failure
*/
public function isInstalled( $pPackage = 'kernel' ) {
return( !empty( $this->mPackages[$pPackage]['installed'] ));
}
/**
* getWebServerUid set global wwwuser and wwwgroup
*
* @access public
* @return void
*/
public function getWebServerUid() {
global $wwwuser, $wwwgroup;
$wwwuser = $wwwgroup = '';
if( KernelTools::is_windows() ) {
$wwwuser = 'SYSTEM';
$wwwgroup = 'SYSTEM';
}
if( function_exists( 'posix_getuid' )) {
$user = @posix_getpwuid( @posix_getuid() );
$group = @posix_getpwuid( @posix_getgid() );
$wwwuser = $user ? $user['name'] : false;
$wwwgroup = $group ? $group['name'] : false;
}
if( !$wwwuser ) {
$wwwuser = 'nobody (or the user account the web server is running under)';
}
if( !$wwwgroup ) {
$wwwgroup = 'nobody (or the group account the web server is running under)';
}
}
/**
* getTablePrefix
*
* @access public
* @return string database adjusted table prefix
*/
public function getTablePrefix() {
global $gBitDbType;
$ret = BIT_DB_PREFIX;
// avoid errors in ADONewConnection() (wrong database driver etc...)
// strip out some schema stuff
switch( $gBitDbType ) {
case "sybase":
// avoid database change messages
ini_set('sybct.min_server_severity', '11');
break;
case "oci8":
case "postgres":
// Do a little prep work for postgres, no break, cause we want default case too
if( preg_match( '/\./', $ret ) ) {
// Assume we want to dump in a schema, so set the search path and nuke the prefix here.
$schema = preg_replace( '/`/', '"', substr( $ret, 0, strpos( $ret, '.' )) );
$quote = strpos( $schema, '"' );
if( $quote !== 0 ) {
$schema = '"'.$schema;
}
// set scope to current schema
$result = $this->mDb->query( "SET search_path TO $schema" );
// return everything after the prefix
$ret = substr( BIT_DB_PREFIX, strrpos( BIT_DB_PREFIX, '`' ) + 1 );
}
break;
}
return $ret;
}
/**
* getVersion reads the installed version from DB during BIT_INSTALL (loadConfig is blocked, so we query directly).
*/
public function getVersion( ?string $pPackage = null, $pDefault = BITWEAVER_VERSION ): string {
$config = empty( $pPackage ) ? 'bitweaver_version' : "package_{$pPackage}_version";
if( !empty( $this->mDb ) ) {
try {
$query = "SELECT `config_value` FROM `" . BIT_DB_PREFIX . "kernel_config` WHERE `config_name`=?";
$result = $this->mDb->getOne( $query, [ $config ] );
if( !empty( $result ) ) {
return $result;
}
} catch( \Throwable $e ) {
// kernel_config may not exist during a fresh install
}
}
return $pDefault;
}
/**
* upgradePackage
*
* @param string $pPackage
* @access public
* @return array|boolean TRUE on success, FALSE on failure - mErrors will contain reason for failure
*/
public function upgradePackage( $pPackage ) {
if( !empty( $pPackage ) && !empty( $this->mUpgrades[$pPackage] )) {
return $this->applyUpgrade( $pPackage, $this->mUpgrades[$pPackage] );
}
return false;
}
/**
* upgradePackageVersion
*
* @param string $pPackage
* @param array $pVersion
* @access public
* @return array|null errors will contain reason for failure
*/
public function upgradePackageVersions( $pPackage ) {
if( !empty( $pPackage ) && !empty( $this->mPackageUpgrades[$pPackage] )) {
// make sure everything is in the right order
uksort( $this->mPackageUpgrades[$pPackage], 'Bitweaver\Install\upgrade_version_sort' );
foreach( array_keys( $this->mPackageUpgrades[$pPackage] ) as $version ) {
// version we are upgrading from
$this->mPackageUpgrades[$pPackage][$version]['from_version'] = $this->getVersion( $pPackage );
// apply upgrade
$errors[$version] = $this->applyUpgrade( $pPackage, $this->mPackageUpgrades[$pPackage][$version]['upgrade'] );
if( !empty( $errors[$version] )) {
return $errors;
}
// if the upgrade ended without incidence, we store the package version.
// this way any successfully applied upgrade can only be applied once.
$this->storeVersion( $pPackage, $version );
}
}
return null;
}
/**
* applyUpgrade
*
* @param string $pPackage
* @param array $pUpgradeHash
* @access public
* @return array empty array on success, array with errors on failure
*/
public function applyUpgrade( $pPackage, $pUpgradeHash ) {
global $gBitDb, $gBitDbType;
$ret = [];
if( !empty( $pUpgradeHash ) && is_array( $pUpgradeHash )) {
// set table prefixes and handle special case of sequence prefixes
$schemaQuote = strrpos( BIT_DB_PREFIX, '`' );
$sequencePrefix = ( $schemaQuote ? substr( BIT_DB_PREFIX, $schemaQuote + 1 ) : BIT_DB_PREFIX );
$tablePrefix = $this->getTablePrefix();
$dict = NewDataDictionary( $gBitDb->mDb, 'firebird' );
$failedcommands = [];
for( $i = 0; $i < count( $pUpgradeHash ); $i++ ) {
if( !is_array( $pUpgradeHash[$i] ) ) {
\Bitweaver\vd( "[$pPackage][$i] is NOT an array" );
\Bitweaver\vd( $pUpgradeHash[$i] );
\Bitweaver\bt();
die;
}
$type = key( $pUpgradeHash[$i] );
$step = &$pUpgradeHash[$i][$type];
switch( $type ) {
case 'DATADICT':
for( $j = 0; $j < count( $step ); $j++ ) {
$dd = &$step[$j];
switch( key( $dd ) ) {
case 'CREATE':
foreach( $dd as $create ) {
foreach( array_keys( $create ) as $tableName ) {
$completeTableName = $tablePrefix.$tableName;
$sql = $dict->CreateTableSQL( $completeTableName, $create[$tableName], 'REPLACE' );
if( $sql && ( $dict->ExecuteSQLArray( $sql, FALSE ) > 0 ) ) {
} else {
$errors[] = 'Failed to create '.$completeTableName;
$failedcommands[] = implode( " ", $sql );
}
}
}
break;
case 'ALTER':
foreach( $dd as $alter ) {
foreach( array_keys( $alter ) as $tableName ) {
$completeTableName = $tablePrefix.$tableName;
$this->mDb->convertQuery( $completeTableName );
foreach( $alter[$tableName] as $from => $flds ) {
$sql = ( is_string( $flds ) )
? $dict->ChangeTableSQL( $completeTableName, $flds )
: $dict->ChangeTableSQL( $completeTableName, [ $flds ] );
if( $sql ) {
for( $sqlIdx = 0; $sqlIdx < count( $sql ); $sqlIdx++ ) {
$this->mDb->convertQuery( $sqlFoo );
}
}
if( $sql && $dict->ExecuteSQLArray( $sql, FALSE ) > 0 ) {
} else {
$errors[] = 'Failed to alter '.$completeTableName.' -> '.$alter[$tableName];
$failedcommands[] = implode( " ", $sql );
}
}
}
}
break;
case 'RENAMETABLE':
foreach( $dd as $rename ) {
foreach( array_keys( $rename ) as $tableName ) {
$completeTableName = $tablePrefix.$tableName;
if( $sql = @$dict->RenameTableSQL( $completeTableName, $tablePrefix.$rename[$tableName] ) ) {
foreach( $sql AS $query ) {
$this->mDb->query( $query );
}
} else {
$errors[] = 'Failed to rename table '.$completeTableName.'.'.$rename[$tableName][0].' to '.$rename[$tableName][1];
$failedcommands[] = implode( " ", $sql );
}
}
}
break;
case 'RENAMECOLUMN':
foreach( $dd as $rename ) {
foreach( array_keys( $rename ) as $tableName ) {
$completeTableName = $tablePrefix.$tableName;
foreach( $rename[$tableName] as $from => $flds ) {
// MySQL needs the fields string, others do not.
// see http://phplens.com/lens/adodb/docs-datadict.htm
$to = substr( $flds, 0, strpos( $flds, ' ') );
if( $sql = @$dict->RenameColumnSQL( $completeTableName, $from, $to, $flds ) ) {
foreach( $sql AS $query ) {
$this->mDb->query( $query );
}
} else {
$errors[] = 'Failed to rename column '.$completeTableName.'.'.$rename[$tableName][0].' to '.$rename[$tableName][1];
$failedcommands[] = implode( " ", $sql );
}
}
}
}
break;
case 'CREATESEQUENCE':
foreach( $dd as $create ) {
foreach( $create as $sequence ) {
$this->mDb->CreateSequence( $sequencePrefix.$sequence );
}
}
break;
case 'RENAMESEQUENCE':
foreach( $dd as $rename ) {
foreach( $rename as $from => $to ) {
if( $gBitDbType != 'mysql' || $this->mDb->tableExists( $tablePrefix.$from ) ) {
if( $id = $this->mDb->GenID( $from ) ) {
$this->mDb->DropSequence( $sequencePrefix.$from );
$this->mDb->CreateSequence( $sequencePrefix.$to, $id );
} else {
$errors[] = 'Failed to rename sequence '.$sequencePrefix.$from.' to '.$sequencePrefix.$to;
$failedcommands[] = implode( " ", $sql );
}
} else {
$this->mDb->CreateSequence( $sequencePrefix.$to, $pUpgradeHash['sequences'][$to]['start'] );
}
}
}
break;
case 'DROPSEQUENCE':
foreach( $dd as $drop ) {
foreach( $drop as $sequence ) {
$this->mDb->DropSequence( $sequencePrefix.$sequence );
}
}
break;
case 'DROPCOLUMN':
foreach( $dd as $drop ) {
foreach( array_keys( $drop ) as $tableName ) {
$completeTableName = $tablePrefix.$tableName;
foreach( $drop[$tableName] as $col ) {
if( $sql = $dict->DropColumnSQL( $completeTableName, $col ) ) {
foreach( $sql AS $query ) {
$this->mDb->query( $query );
}
} else {
$errors[] = 'Failed to drop column '.$completeTableName;
$failedcommands[] = implode( " ", $sql );
}
}
}
}
break;
case 'DROPTABLE':
foreach( $dd as $drop ) {
foreach( $drop as $tableName ) {
$completeTableName = $tablePrefix.$tableName;
$sql = $dict->DropTableSQL( $completeTableName );
if( $sql && $dict->ExecuteSQLArray( $sql ) > 0 ) {
} else {
$errors[] = 'Failed to drop table '.$completeTableName;
$failedcommands[] = implode( " ", $sql );
}
}
}
break;
case 'CREATEINDEX':
foreach( $dd as $indices ) {
foreach( array_keys( $indices ) as $index ) {
$completeTableName = $tablePrefix.$indices[$index][0];
if( $sql = $dict->CreateIndexSQL( $index, $completeTableName, $indices[$index][1], $indices[$index][2] ) ) {
foreach( $sql AS $query ) {
$this->mDb->query( $query );
}
} else {
$errors[] = 'Failed to create index '.$index;
$failedcommands[] = implode( " ", $sql );
}
}
}
break;
}
}
if( !empty( $sql ) ) $sql = null;
break;
case 'QUERY':
uksort( $step, 'Bitweaver\Install\upgrade_query_sort' );
foreach( array_keys( $step ) as $dbType ) {
if( $dbType == 'MYSQL' && preg_match( '/mysql/', $gBitDbType )) {
$sql = $step[$dbType];
unset( $step['SQL92'] );
} elseif( $dbType == 'PGSQL' && preg_match( '/postgres/', $gBitDbType )) {
$sql = $step[$dbType];
unset( $step['SQL92'] );
} elseif( $dbType == 'SQL92' && !empty( $step['SQL92'] )) {
$sql = $step[$dbType];
}
if( !empty( $sql ) ) {
foreach( $sql as $query ) {
if( !$result = $this->mDb->query( $query )) {
$errors[] = 'Failed to execute SQL query';
$failedcommands[] = implode( " ", $sql );
}
}
$sql = NULL;
}
}
break;
case 'PHP':
eval( $step );
break;
case 'POST':
$postSql[] = $step;
break;
}
}
// turn on features that are turned on
// legacy stuff
if( $this->isFeatureActive( 'feature_'.$pPackage )) {
$this->storeConfig( 'package_'.$pPackage, 'y', KERNEL_PKG_NAME );
}
if( !empty( $failedcommands )) {
$ret['errors'] = $errors;
$ret['failedcommands'] = $failedcommands;
}
}
return $ret;
}
/**
* identifyBlobs
*
* @param object $result
* @access public
* @return array
*/
public function identifyBlobs( $result ) {
$blobs = [];
//echo "FieldCount: ".$result->FieldCount()."\n";
for( $i = 0; $i < $result->FieldCount(); $i++ ) {
$field = $result->FetchField($i);
//echo $i."-".$field->name."-".$result->MetaType($field->type)."-".$field->max_length."\n";
// check for blobs
if(( $result->MetaType( $field->type ) == 'B' ) || ( $result->MetaType( $field->type )=='X' && $field->max_length >= 16777215 ))
$blobs[] = $field->name;
}
return $blobs;
}
/**
* convertBlobs enumerate blob fields and encoded
*
* @param BitDb $gDb
* @param array $res
* @param array $blobs
* @access public
* @return void
*/
public function convertBlobs( $gDb, &$res, $blobs ) {
foreach( $blobs as $blob ) {
$res[$blob] = $gDb->dbByteEncode( $res[$blob] );
}
}
}
/**
* check_session_save_path
*
* @access public
* @return void
*/
function check_session_save_path() {
global $errors;
if( ini_get( 'session.save_handler' ) == 'files' ) {
$save_path = ini_get( 'session.save_path' );
if( !is_dir( $save_path )) {
$errors .= "The directory '$save_path' does not exist or PHP is not allowed to access it (check session.save_path or open_basedir entries in php.ini).\n";
} elseif( !KernelTools::bw_is_writeable( $save_path )) {
$errors .= "The directory '$save_path' is not writeable.\n";
}
if( $errors ) {
$save_path = KernelTools::get_temp_dir();
if (is_dir($save_path) && KernelTools::bw_is_writeable($save_path)) {
ini_set('session.save_path', $save_path);
$errors = '';
}
}
}
}
/**
* makeConnection
*
* @param string $gBitDbType
* @param string $gBitDbHost
* @param string $gBitDbUser
* @param string $gBitDbPassword
* @param string $gBitDbName
* @access public
* @return \ADOConnection
*/
function makeConnection( $gBitDbType, $gBitDbHost, $gBitDbUser, $gBitDbPassword, $gBitDbName ) {
$gDb = ADONewConnection( $gBitDbType );
if( !$gDb->Connect( $gBitDbHost, $gBitDbUser, $gBitDbPassword, $gBitDbName )) {
echo $gDb->ErrorMsg()."\n";
die;
}
global $gBitDbCaseSensitivity;
$gDb->mCaseSensitive = $gBitDbCaseSensitivity;
$gDb->SetFetchMode( ADODB_FETCH_ASSOC );
return $gDb;
}
/**
* upgrade_package_sort sort packages before they are upgraded
*
* @param string $a
* @param string $b
* @access public
* @return numeric sort direction
*/
function upgrade_package_sort( $a, $b ) {
global $gBitInstaller;
$aa = $gBitInstaller->mPackages[$a];
$bb = $gBitInstaller->mPackages[$b];
if(( $aa['required'] && $bb['required'] ) || ( !$aa['required'] && !$bb['required'] )) {
return 0;
} elseif( $aa['required'] && !$bb['required'] ) {
return -1;
} elseif( !$aa['required'] && $bb['required'] ) {
return 1;
}
return 0;
}
/**
* upgrade_version_sort sort upgrades based on version number
*
* @param string $a
* @param string $b
* @access public
* @return numeric sort direction
*/
function upgrade_version_sort( $a, $b ) {
return version_compare( $a, $b );
}
/**
* upgrade_query_sort sort queries that SQL92 queries are called last
*
* @param string $a
* @param string $b
* @access public
* @return numeric sort direction
*/
function upgrade_query_sort( $a, $b ) {
if( $a == 'SQL92' ) {
return 1;
} elseif( $b == 'SQL92' ) {
return -1;
}
return 0;
}
|