2020-06-17 02:26:04 +02:00
< ? php
require_once '../mysql_connect.php' ;
use RedBeanPHP\Facade as RedBean ;
print 'Begin update v4.7.0...' . PHP_EOL ;
// Update User table
2020-06-18 12:08:20 +02:00
print '[1/4] Updating user table...' . PHP_EOL ;
2020-06-17 02:26:04 +02:00
if ( $mysql -> query ( " SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'user' AND COLUMN_NAME = 'not_registered' AND TABLE_SCHEMA = ' $mysql_db ' " ) -> num_rows == 0 ) {
$mysql -> query ( " ALTER TABLE user ADD not_registered tinyint(1) " );
2020-06-19 19:37:15 +02:00
$mysql -> query ( " UPDATE user SET not_registered = null " );
2020-06-17 02:26:04 +02:00
} else {
print '-not_registered column already exists' . PHP_EOL ;
}
2020-06-24 07:12:13 +02:00
if ( ! Setting :: getSetting ( 'user-system-enabled' ) -> isNull () && ! Setting :: getSetting ( 'user-system-enabled' ) -> getValue ()) {
2020-06-18 12:08:20 +02:00
$ticketList = Ticket :: getAll ();
foreach ( $ticketList as $ticket ) {
if ( $ticket -> authorStaff ) {
continue ;
}
$userInstance = User :: getDataStore ( $ticket -> authorEmail , 'email' );
2020-06-24 07:12:13 +02:00
$ticketInstance = Ticket :: getByTicketNumber ( $ticket -> ticketNumber );
2020-06-18 12:08:20 +02:00
if ( $userInstance -> isNull ()) {
$userInstance = new User ();
$password = Hashing :: generateRandomToken ();
$userInstance -> setProperties ([
'name' => $ticket -> authorName ,
'signupDate' => Date :: getCurrentDate (),
'tickets' => 0 ,
'email' => $ticket -> authorEmail ,
'password' => Hashing :: hashPassword ( $password ),
2020-06-24 07:12:13 +02:00
'notRegistered' => 1 ,
2020-06-18 12:08:20 +02:00
'verificationToken' => null
]);
$userInstance -> store ();
}
2020-06-24 07:12:13 +02:00
2020-06-18 12:08:20 +02:00
$userInstance -> tickets = $userInstance -> tickets + 1 ;
$userInstance -> sharedTicketList -> add ( $ticket );
$userInstance -> store ();
2020-06-24 07:12:13 +02:00
$ticketInstance -> author = $userInstance ;
$ticketInstance -> store ();
2020-06-18 12:08:20 +02:00
}
} else {
print '-The tickets created already have owner Users' . PHP_EOL ;
}
2020-06-17 02:26:04 +02:00
// Update mailtemplate table
2020-06-18 12:08:20 +02:00
print '[2/4] Updating mailtemplate table...' . PHP_EOL ;
2020-06-17 02:26:04 +02:00
if ( $mysql -> query ( " SELECT * FROM mailtemplate WHERE template='USER_SYSTEM_DISABLED' " ) -> num_rows != 0 ) {
$mysql -> query ( " DELETE FROM mailtemplate WHERE template='USER_SYSTEM_DISABLED' " );
} else {
print '-user_system_disabled template is already deleted' . PHP_EOL ;
}
if ( $mysql -> query ( " SELECT * FROM mailtemplate WHERE template='USER_SYSTEM_ENABLED' " ) -> num_rows != 0 ) {
$mysql -> query ( " DELETE FROM mailtemplate WHERE template='USER_SYSTEM_ENABLED' " );
} else {
print '-user_system_enabled template is already deleted' . PHP_EOL ;
}
2020-06-18 12:08:20 +02:00
// Update Department table
print '[3/4] Updating department table...' . PHP_EOL ;
if ( $mysql -> query ( " SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'department' AND COLUMN_NAME = 'private' AND TABLE_SCHEMA = ' $mysql_db ' " ) -> num_rows == 0 ) {
$mysql -> query ( " ALTER TABLE department ADD private tinyint(1) " );
$mysql -> query ( " UPDATE department SET private = 0 " );
} else {
print 'private column already exists' . PHP_EOL ;
}
2020-06-17 02:26:04 +02:00
// Update setting table
2020-06-18 12:08:20 +02:00
print '[4/4] Updating setting table...' . PHP_EOL ;
2020-06-17 02:26:04 +02:00
if ( $mysql -> query ( " SELECT * FROM setting WHERE name='mandatory-login' " ) -> num_rows == 0 ) {
$userSystemEnabled = $mysql -> query ( " SELECT * FROM setting WHERE name='user-system-enabled' " );
if ( $userSystemEnabled -> fetch_array ( MYSQLI_ASSOC )[ 'value' ]){
$mysql -> query ( " INSERT into setting VALUES(NULL, 'mandatory-login', '1') " );
} else {
$mysql -> query ( " INSERT into setting VALUES(NULL, 'mandatory-login', '0') " );
2020-06-19 19:37:15 +02:00
$mysql -> query ( " UPDATE setting SET value=1 where name='registration' " );
2020-06-17 02:26:04 +02:00
}
} else {
print '-Mandatory-login already exists' . PHP_EOL ;
}
if ( $mysql -> query ( " SELECT * FROM setting WHERE name='default-department-id' " ) -> num_rows == 0 ) {
2020-06-18 12:08:20 +02:00
$publicDepartment = $mysql -> query ( " SELECT * FROM department WHERE private= 0 OR private IS NULL " );
2020-06-17 02:26:04 +02:00
if ( $publicDepartment -> num_rows != 0 ){
2020-06-19 19:37:15 +02:00
$query = " INSERT into setting VALUES(NULL, 'default-department-id', " . $publicDepartment -> fetch_array ( MYSQLI_BOTH )[ 'id' ] . " ) " ;
2020-06-18 12:08:20 +02:00
2020-06-17 02:26:04 +02:00
$mysql -> query ( $query );
} else {
print '-Fail DEFAULT-DEPARTMENT-ID update. A public department is required' ;
}
} else {
print '-Default-department-id already exists' . PHP_EOL ;
}
if ( $mysql -> query ( " SELECT * FROM setting WHERE name='default-is-locked' " ) -> num_rows == 0 ) {
$mysql -> query ( " INSERT into setting VALUES(NULL, 'default-is-locked', '0') " );
} else {
print '-Default-is-locked already exists' . PHP_EOL ;
}
if ( $mysql -> query ( " SELECT * FROM setting WHERE name='user-system-enabled' " ) -> num_rows != 0 ) {
$mysql -> query ( " DELETE FROM setting WHERE name='user-system-enabled' " );
} else {
2020-06-19 19:37:15 +02:00
print '-User-system-enabled is already deleted' . PHP_EOL ;
2020-06-17 02:26:04 +02:00
}
2020-06-18 12:08:20 +02:00
print 'Update Completed!' . PHP_EOL ;
2020-06-24 07:12:13 +02:00