getByUserName( $user_name ); if ( $ulf->getRecordCount() == 1 ) { echo "Found user, apply administrator permissions...\n"; ob_flush(); $u_obj = $ulf->getCurrent(); //Create new Permission Group just for this purpose. $pf = new PermissionFactory(); $pf->StartTransaction(); //Apply all preset flags, including 0 => "system" $preset_flags = array_merge( [ 0 ], array_keys( $pf->getOptions( 'preset_flags' ) ) ); $pcf = new PermissionControlFactory(); $pcf->setCompany( $u_obj->getCompany() ); $pcf->setLevel( 100 ); $pcf->setName( 'Administrator Fix (' . rand( 1, 1000 ) . ')' ); $pcf->setDescription( 'Created By set_admin_permissions.php' ); if ( $pcf->isValid() ) { $pcf_id = $pcf->Save( false ); $pcf->setUser( [ $u_obj->getId() ] ); $pcf->Save(); if ( $pf->applyPreset( $pcf_id, 40, $preset_flags ) == true ) { echo "Success!\n"; } } //$pf->FailTransaction(); $pf->CommitTransaction(); } else if ( $ulf->getRecordCount() > 2 ) { echo "Found more then one user with the same user name, not updating permissions!\n"; } else { echo "User name not found!\n"; } } } //Debug::Display(); Debug::writeToLog(); ?>