diff --git a/cli/add-user.php b/cli/add-user.php index 14e5683..d0bd7f4 100755 --- a/cli/add-user.php +++ b/cli/add-user.php @@ -1,75 +1,75 @@ #!/usr/bin/php . // allowed only from command line interface if( ! isset( $argv[ 0 ] ) ) { exit( 1 ); } // autoload the framework require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'load.php'; // command line arguments $opts = getopt( 'h', [ 'uid:', 'role:', 'pwd:', 'force::', 'help', ] ); // show help if( ! isset( $opts[ 'uid' ], $opts[ 'pwd' ], $opts[ 'role' ] ) || isset( $opts[ 'help' ] ) || isset( $opts[ 'h' ] ) ) { printf( "Usage: %s [OPTIONS]\n", $argv[ 0 ] ); echo "OPTIONS:\n"; echo " --uid=UID user UID\n"; - echo " --role=ROLE user role (user|admin)\n"; + echo " --role=ROLE user role (user|admin|translator)\n"; echo " --pwd=PASSWORD password\n"; echo " --force update the user password if exists\n"; echo " -h --help show this help and exit\n"; exit( 0 ); } // look for existing user $user = User::factoryFromUID( $opts[ 'uid' ] ) ->select( User::ID ) ->queryRow(); if( $user && ! isset( $opts[ 'force' ] ) ) { printf( "User %s already exist\n", $opts[ 'uid' ] ); exit( 1 ); } $pwd = User::encryptPassword( $opts[ 'pwd' ] ); if( $user ) { query_update( User::T, [ new DBCol( User::PASSWORD, $pwd, 's' ), ], sprintf( '%s = %d', User::ID, $user->getUserID() ) ); } else { insert_row( User::T, [ new DBCol( User::UID, $opts[ 'uid' ], 's' ), new DBCol( User::ROLE, $opts[ 'role' ], 's' ), new DBCol( User::PASSWORD, $pwd, 's' ), new DBCol( User::IS_ACTIVE, 1, 'd' ), ] ); } diff --git a/documentation/database/patches/patch-6.sql b/documentation/database/patches/patch-6.sql new file mode 100644 index 0000000..6403608 --- /dev/null +++ b/documentation/database/patches/patch-6.sql @@ -0,0 +1 @@ +ALTER TABLE `{$prefix}user` CHANGE `user_role` `user_role` ENUM('admin','user','translator') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'user';