public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
 {
     // Maybe we should check that no other user with userid == 0 exists
     $oUser = new UserLocal();
     $oUser->Set('login', $sAdminUser);
     $oUser->Set('password', $sAdminPwd);
     $oUser->Set('contactid', 1);
     // one is for root !
     $oUser->Set('language', $sLanguage);
     // Language was chosen during the installation
     // Create a change to record the history of the User object
     $oChange = MetaModel::NewObject("CMDBChange");
     $oChange->Set("date", time());
     $oChange->Set("userinfo", "Initialization");
     $iChangeId = $oChange->DBInsert();
     // Now record the admin user object
     $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true);
     $this->SetupUser($iUserId, true);
     return true;
 }
 public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
 {
     // Create a change to record the history of the User object
     $oChange = MetaModel::NewObject("CMDBChange");
     $oChange->Set("date", time());
     $oChange->Set("userinfo", "Initialization");
     $iChangeId = $oChange->DBInsert();
     $oOrg = new Organization();
     $oOrg->Set('name', 'My Company/Department');
     $oOrg->Set('code', 'SOMECODE');
     //		$oOrg->Set('status', 'implementation');
     //$oOrg->Set('parent_id', xxx);
     $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange, true);
     // Location : optional
     //$oLocation = new bizLocation();
     //$oLocation->Set('name', 'MyOffice');
     //$oLocation->Set('status', 'implementation');
     //$oLocation->Set('org_id', $iOrgId);
     //$oLocation->Set('severity', 'high');
     //$oLocation->Set('address', 'my building in my city');
     //$oLocation->Set('country', 'my country');
     //$oLocation->Set('parent_location_id', xxx);
     //$iLocationId = $oLocation->DBInsertNoReload();
     $oContact = new Person();
     $oContact->Set('name', 'My last name');
     $oContact->Set('first_name', 'My first name');
     //$oContact->Set('status', 'available');
     $oContact->Set('org_id', $iOrgId);
     $oContact->Set('email', '*****@*****.**');
     //$oContact->Set('phone', '');
     //$oContact->Set('location_id', $iLocationId);
     //$oContact->Set('employee_number', '');
     $iContactId = $oContact->DBInsertTrackedNoReload($oChange, true);
     $oUser = new UserLocal();
     $oUser->Set('login', $sAdminUser);
     $oUser->Set('password', $sAdminPwd);
     $oUser->Set('contactid', $iContactId);
     $oUser->Set('language', $sLanguage);
     // Language was chosen during the installation
     $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true);
     // Add this user to the very specific 'admin' profile
     $oUserProfile = new URP_UserProfile();
     $oUserProfile->Set('userid', $iUserId);
     $oUserProfile->Set('profileid', ADMIN_PROFILE_ID);
     $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
     $oUserProfile->DBInsertTrackedNoReload($oChange, true);
     return true;
 }
 public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
 {
     CMDBObject::SetTrackInfo('Initialization');
     $oChange = CMDBObject::GetCurrentChange();
     $iContactId = 0;
     // Support drastic data model changes: no organization class (or not writable)!
     if (MetaModel::IsValidClass('Organization') && !MetaModel::IsAbstract('Organization')) {
         $oOrg = new Organization();
         $oOrg->Set('name', 'My Company/Department');
         $oOrg->Set('code', 'SOMECODE');
         $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange, true);
         // Support drastic data model changes: no Person class  (or not writable)!
         if (MetaModel::IsValidClass('Person') && !MetaModel::IsAbstract('Person')) {
             $oContact = new Person();
             $oContact->Set('name', 'My last name');
             $oContact->Set('first_name', 'My first name');
             if (MetaModel::IsValidAttCode('Person', 'org_id')) {
                 $oContact->Set('org_id', $iOrgId);
             }
             if (MetaModel::IsValidAttCode('Person', 'phone')) {
                 $oContact->Set('phone', '+00 000 000 000');
             }
             $oContact->Set('email', '*****@*****.**');
             $iContactId = $oContact->DBInsertTrackedNoReload($oChange, true);
         }
     }
     $oUser = new UserLocal();
     $oUser->Set('login', $sAdminUser);
     $oUser->Set('password', $sAdminPwd);
     if (MetaModel::IsValidAttCode('UserLocal', 'contactid') && $iContactId != 0) {
         $oUser->Set('contactid', $iContactId);
     }
     $oUser->Set('language', $sLanguage);
     // Language was chosen during the installation
     // Add this user to the very specific 'admin' profile
     $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => ADMIN_PROFILE_NAME), true);
     if (is_object($oAdminProfile)) {
         $oUserProfile = new URP_UserProfile();
         //$oUserProfile->Set('userid', $iUserId);
         $oUserProfile->Set('profileid', $oAdminProfile->GetKey());
         $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
         //$oUserProfile->DBInsertTrackedNoReload($oChange, true /* skip security */);
         $oSet = DBObjectSet::FromObject($oUserProfile);
         $oUser->Set('profile_list', $oSet);
     }
     $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true);
     return true;
 }
Exemplo n.º 4
0
 protected function DoExecute()
 {
     $oUser = new UserLocal();
     $oUser->Set('login', 'patator' . time());
     $oUser->Set('password', 'patator');
     //$oUser->Set('contactid', 0);
     //$oUser->Set('language', $sLanguage);
     $sLinkSetSpec = "profileid:10;reason:service manager|profileid->name:Problem Manager;'reason:problem manager;glandeur";
     $oAttDef = MetaModel::GetAttributeDef('UserLocal', 'profile_list');
     $oSet = $oAttDef->MakeValueFromString($sLinkSetSpec, $bLocalizedValue = false);
     $oUser->Set('profile_list', $oSet);
     // Create a change to record the history of the User object
     $this->ObjectToDB($oUser, $bReload = true);
     echo "<p>Created: {$oUser->GetHyperLink()}</p>";
 }