function postInstall() { Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); //Add Calendar Based Accruals to Cron. $maint_base_path = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'maint' . DIRECTORY_SEPARATOR; if (PHP_OS == 'WINNT') { $cron_job_base_command = 'php-win.exe ' . $maint_base_path; } else { $cron_job_base_command = 'php ' . $maint_base_path; } Debug::text('Cron Job Base Command: ' . $cron_job_base_command, __FILE__, __LINE__, __METHOD__, 9); $cjf = new CronJobFactory(); $cjf->setName('AddAccrualPolicyTime'); $cjf->setMinute(30); $cjf->setHour(1); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'AddAccrualPolicyTime.php'); $cjf->Save(); return TRUE; }
function postInstall() { global $cache; Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); Debug::text('l: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); if (is_array($this->station_users) and count($this->station_users) > 0) { foreach ($this->station_users as $station_id => $user_ids) { //Get station object. $slf = new StationListFactory(); $slf->getById($station_id); if ($slf->getRecordCount() > 0) { $s_obj = $slf->getCurrent(); if (in_array('-1', $user_ids)) { //All users allowed $s_obj->setGroupSelectionType(10); $s_obj->setBranchSelectionType(10); $s_obj->setDepartmentSelectionType(10); } else { //Only specific users allowed $s_obj->setIncludeUser($user_ids); } if ($s_obj->isValid()) { $s_obj->Save(); } } } } unset($this->station_users); //Add currency updating to cron. $maint_base_path = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'maint' . DIRECTORY_SEPARATOR; if (PHP_OS == 'WINNT') { $cron_job_base_command = 'php-win.exe ' . $maint_base_path; } else { $cron_job_base_command = 'php ' . $maint_base_path; } Debug::text('Cron Job Base Command: ' . $cron_job_base_command, __FILE__, __LINE__, __METHOD__, 9); $cjf = new CronJobFactory(); $cjf->setName('TimeClockSync'); $cjf->setMinute('*'); $cjf->setHour('*'); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'TimeClockSync.php'); $cjf->Save(); return TRUE; }
function postInstall() { Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); //Go through all pay period schedules and update the annual pay period column $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getAll(); if ($ppslf->getRecordCount() > 0) { foreach ($ppslf as $pps_obj) { $pps_obj->setAnnualPayPeriods($pps_obj->calcAnnualPayPeriods()); if ($pps_obj->isValid()) { $pps_obj->Save(); } } } //Go through all employee wages and update HourlyRate to the accurate annual hourly rate. //**Handle this in 1034A postInstall() instead, as it needs to handle incorrect effective_dates properly. /* $uwlf = new UserWageListFactory(); $uwlf->getAll(); if ( $uwlf->getRecordCount() > 0 ) { foreach( $uwlf as $uw_obj ) { $uw_obj->setHourlyRate( $uw_obj->calcHourlyRate( time(), TRUE ) ); if ( $uw_obj->isValid() ) { $uw_obj->Save(); } } } */ //Upgrade to new hierarchy format. $clf = new CompanyListFactory(); $clf->getAll(); if ($clf->getRecordCount() > 0) { foreach ($clf as $c_obj) { if ($c_obj->getStatus() != 30) { /* if ( !($c_obj->getId() == 1052) ) { //$c_obj->getId() == 1009 OR $c_obj->getId() == 1087 OR continue; } */ $company_id = $c_obj->getId(); Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10); $hclf = new HierarchyControlListFactory(); $hclf->StartTransaction(); $hclf->getByCompanyId($company_id); if ($hclf->getRecordCount() > 0) { foreach ($hclf as $hc_obj) { $paths_to_root = array(); $hierarchy_id = $hc_obj->getId(); $hlf = new HierarchyListFactory(); $hierarchy_users = $hlf->getByCompanyIdAndHierarchyControlId($company_id, $hierarchy_id); if (is_array($hierarchy_users) and count($hierarchy_users) > 0) { $hotlf = new HierarchyObjectTypeListFactory(); $hotlf->getByHierarchyControlId($hierarchy_id); if ($hotlf->getRecordCount() > 0) { foreach ($hotlf as $hot_obj) { $object_types[$hierarchy_id][] = $hot_obj->getObjectType(); } } foreach ($hierarchy_users as $hierarchy_user_arr) { Debug::Text(' Checking User ID: ' . $hierarchy_user_arr['id'], __FILE__, __LINE__, __METHOD__, 10); $id = $hierarchy_user_arr['id']; $tmp_id = $id; $i = 0; do { Debug::Text(' Iteration...', __FILE__, __LINE__, __METHOD__, 10); $hlf_b = new HierarchyListFactory(); $parents = $hlf_b->getParentLevelIdArrayByHierarchyControlIdAndUserId($hierarchy_id, $tmp_id); sort($parents); $level = $hlf_b->getFastTreeObject()->getLevel($tmp_id) - 1; if (is_array($parents) and count($parents) > 0) { $parent_users = array(); foreach ($parents as $user_id) { $parent_users[] = $user_id; unset($user); } $parent_groups[$level] = $parent_users; unset($parent_users); } if (isset($parents[0])) { $tmp_id = $parents[0]; } $i++; } while (is_array($parents) and count($parents) > 0 and $i < 100); if (isset($parent_groups)) { $serialized_path = serialize($parent_groups); $paths_to_root[$serialized_path][] = $id; unset($serialized_path); } unset($parent_groups, $parents); } } Debug::Arr($paths_to_root, ' Paths To Root: ', __FILE__, __LINE__, __METHOD__, 10); //Decode path_to_root array if (isset($paths_to_root) and count($paths_to_root) > 0) { foreach ($paths_to_root as $serialized_path => $children) { $path_arr = unserialize($serialized_path); $decoded_paths[] = array('hierarchy_control_id' => $hierarchy_id, 'path' => $path_arr, 'children' => $children); } unset($path_arr, $children); Debug::Arr($decoded_paths, ' Decoded Paths: ', __FILE__, __LINE__, __METHOD__, 10); if (isset($decoded_paths) and is_array($decoded_paths)) { foreach ($decoded_paths as $decoded_path) { Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10); //Create new hierarchy_control $hcf = new HierarchyControlFactory(); $hcf->setCompany($company_id); $hcf->setObjectType($object_types[$decoded_path['hierarchy_control_id']]); //Generate meaningful name $name = FALSE; if (isset($decoded_path['path']) and is_array($decoded_path['path'])) { ksort($decoded_path['path']); //Sort by level. foreach ($decoded_path['path'] as $level => $superior_ids) { foreach ($superior_ids as $superior_id) { $ulf = new UserListFactory(); $ulf->getById($superior_id); if ($ulf->getRecordCount() > 0) { $name[] = $level . '. ' . $ulf->getCurrent()->getFullName(); } } } unset($level, $superior_ids, $superior_id); } if (isset($name)) { $name = $hc_obj->getName() . ' ' . implode(', ', $name) . ' (#' . rand(1000, 9999) . ')'; } else { $name = $hc_obj->getName() . ' (#' . rand(1000, 9999) . ')'; } $hcf->setName(substr($name, 0, 249)); $hcf->setDescription(TTi18n::getText('Automatically created by TimeTrex')); if ($hcf->isValid()) { $hc_id = $hcf->Save(FALSE); Debug::Text('Hierarchy Control ID: ' . $hc_id, __FILE__, __LINE__, __METHOD__, 10); $hcf->setUser($decoded_path['children']); if (isset($decoded_path['path']) and is_array($decoded_path['path'])) { foreach ($decoded_path['path'] as $level => $superior_ids) { foreach ($superior_ids as $superior_id) { $hlf = new HierarchyLevelFactory(); $hlf->setHierarchyControl($hc_id); $hlf->setLevel($level); $hlf->setUser($superior_id); if ($hlf->isValid()) { $hlf->Save(); Debug::Text('Saving Level Row ID... User ID: ' . $superior_id, __FILE__, __LINE__, __METHOD__, 10); } } } unset($level, $superior_ids, $superior_id); } } } } unset($decoded_paths); } //Delete existing hierarchy control. $hc_obj->setDeleted(TRUE); if ($hc_obj->isValid() == TRUE) { $hc_obj->Save(); } } } //$hclf->FailTransaction(); $hclf->CommitTransaction(); } } } //Go through each permission group, and enable break policies for anyone who can see meal policies $clf = new CompanyListFactory(); $clf->getAll(); if ($clf->getRecordCount() > 0) { foreach ($clf as $c_obj) { Debug::text('Company: ' . $c_obj->getName(), __FILE__, __LINE__, __METHOD__, 9); if ($c_obj->getStatus() != 30) { $pclf = new PermissionControlListFactory(); $pclf->getByCompanyId($c_obj->getId()); if ($pclf->getRecordCount() > 0) { foreach ($pclf as $pc_obj) { Debug::text('Permission Group: ' . $pc_obj->getName(), __FILE__, __LINE__, __METHOD__, 9); $plf = new PermissionListFactory(); $plf->getByCompanyIdAndPermissionControlIdAndSectionAndName($c_obj->getId(), $pc_obj->getId(), 'meal_policy', 'enabled'); if ($plf->getRecordCount() > 0) { Debug::text('Found permission group with meal policy enabled: ' . $plf->getCurrent()->getValue(), __FILE__, __LINE__, __METHOD__, 9); $pc_obj->setPermission(array('break_policy' => array('enabled' => TRUE, 'view' => TRUE, 'add' => TRUE, 'edit' => TRUE, 'delete' => TRUE))); } else { Debug::text('Permission group does NOT have meal policy enabled...', __FILE__, __LINE__, __METHOD__, 9); } } } } } } //Add MiscDaily cronjob to database. $cjf = new CronJobFactory(); $cjf->setName('MiscDaily'); $cjf->setMinute(55); $cjf->setHour(1); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand('MiscDaily.php'); $cjf->Save(); //Add MiscWeekly cronjob to database. $cjf = new CronJobFactory(); $cjf->setName('MiscWeekly'); $cjf->setMinute(55); $cjf->setHour(1); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('0'); //Sunday morning. $cjf->setCommand('MiscWeekly.php'); $cjf->Save(); return TRUE; }
function postInstall() { global $cache; Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); //Configure currencies for Standard Edition. if ($this->getIsUpgrade() == TRUE) { $clf = new CompanyListFactory(); $clf->StartTransaction(); $clf->getAll(); if ($clf->getRecordCount() > 0) { foreach ($clf as $c_obj) { if ($c_obj->getStatus() == 10) { //Converting to new Accrual Policy table. Debug::text('Converting to new Accrual Policy Table: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9); $pglf = new PolicyGroupListFactory(); $pglf->getByCompanyId($c_obj->getId()); if ($pglf->getRecordCount() > 0) { foreach ($pglf as $pg_obj) { Debug::text('Accrual Policy ID: ' . $pg_obj->getColumn('accrual_policy_id'), __FILE__, __LINE__, __METHOD__, 9); if ($pg_obj->getColumn('accrual_policy_id') != '' and $pg_obj->getColumn('accrual_policy_id') != 0) { $pg_obj->setAccrualPolicy(array($pg_obj->getColumn('accrual_policy_id'))); if ($pg_obj->isValid()) { $pg_obj->Save(); } } } } Debug::text('Adding Currency Information to Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9); $crlf = new CurrencyListFactory(); $crlf->getByCompanyId($c_obj->getId()); if ($crlf->getRecordCount() == 0) { $cf = new CurrencyFactory(); $country_to_currency_map_arr = $cf->getOptions('country_currency'); if (isset($country_to_currency_map_arr[$c_obj->getCountry()])) { $base_currency = $country_to_currency_map_arr[$c_obj->getCountry()]; Debug::text('Found Base Currency For Country: ' . $c_obj->getCountry() . ' Currency: ' . $base_currency, __FILE__, __LINE__, __METHOD__, 9); } else { Debug::text('DID NOT Find Base Currency For Country: ' . $c_obj->getCountry() . ' Using default USD.', __FILE__, __LINE__, __METHOD__, 9); $base_currency = 'USD'; } $cf->setCompany($c_obj->getId()); $cf->setStatus(10); $cf->setName($base_currency); $cf->setISOCode($base_currency); $cf->setConversionRate('1.000000000'); $cf->setAutoUpdate(FALSE); $cf->setBase(TRUE); $cf->setDefault(TRUE); if ($cf->isValid()) { $base_currency_id = $cf->Save(); Debug::text('Base Currency ID: ' . $base_currency_id, __FILE__, __LINE__, __METHOD__, 10); //Set Employee Hire Defaults. $udlf = new UserDefaultListFactory(); $udlf->getByCompanyId($c_obj->getId()); if ($udlf->getRecordCount() > 0) { $ud_obj = $udlf->getCurrent(); $ud_obj->setCurrency($base_currency_id); $ud_obj->setLanguage('en'); if ($ud_obj->isValid()) { $ud_obj->Save(); } } unset($udlf, $ud_obj); if (is_numeric($base_currency_id)) { $ulf = new UserListFactory(); $ulf->getByCompanyId($c_obj->getId()); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $u_obj) { $user_id = $u_obj->getID(); Debug::text('Setting Base Currency For User: '******' ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); $u_obj->setCurrency($base_currency_id); if ($u_obj->isValid()) { if ($u_obj->Save() == TRUE) { //Set User Default Language $uplf = new UserPreferenceListFactory(); $uplf->getByUserIDAndCompanyID($user_id, $c_obj->getId()); if ($uplf->getRecordCount() > 0) { $up_obj = $uplf->getCurrent(); $up_obj->setLanguage('en'); //Englist if ($up_obj->isValid()) { $up_obj->Save(); } } unset($uplf, $up_obj); Debug::text(' Setting Base Currency for Pay Stubs, User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); //Change all pay stubs for this user to the base currency. //Do this in a single query for speed purposes. $ph = array('currency_id' => $base_currency_id, 'currency_rate' => '1.000000000', 'user_id' => $user_id); $query = 'update pay_stub set currency_id = ?, currency_rate = ? where user_id = ?'; Debug::text(' Pay Stub Currency Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10); $u_obj->db->Execute($query, $ph); /* $pslf = new PayStubListFactory(); $pslf->getByUserIdAndCompanyId( $user_id, $c_obj->getId() ); if ( $pslf->getRecordCount() > 0 ) { foreach( $pslf as $ps_obj ) { //Debug::text(' Setting Base Currency for Pay Stub ID: '. $ps_obj->getId(), __FILE__, __LINE__, __METHOD__,10); $ps_obj->setCurrency( $base_currency_id ); if ( $ps_obj->isValid() ) { $ps_obj->setEnableLinkedAccruals( FALSE ); $ps_obj->setEnableCalcYTD( FALSE ); $ps_obj->setEnableProcessEntries( FALSE ); $ps_obj->Save(); } unset($ps_obj); } } unset($pslf); */ } else { Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); } unset($u_obj, $user_id); } } unset($ulf); } } unset($cf); } } else { Debug::text('Company is not active! ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); } unset($c_obj, $base_currency, $base_currency_id, $crlf); } } //$clf->FailTransaction(); $clf->CommitTransaction(); } //Add currency updating to cron. $maint_base_path = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'maint' . DIRECTORY_SEPARATOR; if (PHP_OS == 'WINNT') { $cron_job_base_command = 'php-win.exe ' . $maint_base_path; } else { $cron_job_base_command = 'php ' . $maint_base_path; } Debug::text('Cron Job Base Command: ' . $cron_job_base_command, __FILE__, __LINE__, __METHOD__, 9); $cjf = new CronJobFactory(); $cjf->setName('UpdateCurrencyRates'); $cjf->setMinute(45); $cjf->setHour(1); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'UpdateCurrencyRates.php'); $cjf->Save(); return TRUE; }
function postInstall() { global $config_vars; Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); $maint_base_path = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'maint' . DIRECTORY_SEPARATOR; if (PHP_OS == 'WINNT') { $cron_job_base_command = 'php-win.exe ' . $maint_base_path; } else { $cron_job_base_command = 'php ' . $maint_base_path; } Debug::text('Cron Job Base Command: ' . $cron_job_base_command, __FILE__, __LINE__, __METHOD__, 9); // >> /dev/null 2>&1 $cjf = new CronJobFactory(); $cjf->setName('AddPayPeriod'); $cjf->setMinute(0); $cjf->setHour(0); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'AddPayPeriod.php'); $cjf->Save(); $cjf = new CronJobFactory(); $cjf->setName('AddUserDate'); $cjf->setMinute(15); $cjf->setHour(0); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'AddUserDate.php'); $cjf->Save(); $cjf = new CronJobFactory(); $cjf->setName('calcExceptions'); $cjf->setMinute(30); $cjf->setHour(0); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'calcExceptions.php'); $cjf->Save(); $cjf = new CronJobFactory(); $cjf->setName('AddRecurringPayStubAmendment'); $cjf->setMinute(45); $cjf->setHour(0); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'AddRecurringPayStubAmendment.php'); $cjf->Save(); $cjf = new CronJobFactory(); $cjf->setName('AddRecurringHoliday'); $cjf->setMinute(55); $cjf->setHour(0); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'AddRecurringHoliday.php'); $cjf->Save(); $cjf = new CronJobFactory(); $cjf->setName('UserCount'); $cjf->setMinute(15); $cjf->setHour(1); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'UserCount.php'); $cjf->Save(); $cjf = new CronJobFactory(); $cjf->setName('AddRecurringScheduleShift'); $cjf->setMinute('20,50'); $cjf->setHour('*'); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'AddRecurringScheduleShift.php'); $cjf->Save(); $cjf = new CronJobFactory(); $cjf->setName('CheckForUpdate'); $cjf->setMinute(rand(0, 59)); //Random time once a day for load balancing $cjf->setHour(rand(0, 23)); //Random time once a day for load balancing $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'CheckForUpdate.php'); $cjf->Save(); return TRUE; }