getAll(); if ( $clf->getRecordCount() > 0 ) { foreach ( $clf as $c_obj ) { if ( isset( $company_id ) && $company_id != '' && $company_id != $c_obj->getId() ) { continue; } if ( $c_obj->getStatus() != 30 ) { Debug::text( 'Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getID(), __FILE__, __LINE__, __METHOD__, 10 ); echo 'Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getID() . "\n"; $rsclf = new RecurringScheduleControlListFactory(); // // Add new recurring schedules. // $rsclf->getByCompanyIdAndStartDateAndEndDate( $c_obj->getId(), $initial_start_date, $initial_end_date ); if ( $rsclf->getRecordCount() > 0 ) { Debug::text( 'Recurring Schedule Control List Record Count: ' . $rsclf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10 ); foreach ( $rsclf as $rsc_obj ) { $rsclf->StartTransaction(); // Wrap each individual schedule in its own transaction instead. //Since cron jobs run in system timezone (ie: PST8PDT) and date_stamp and start_date/end_date (timestamptz) columns being different data types //we need to try to switch into a timezone at least within the same day as the final timezone before we get the recurring schedules. //Once we do something with the date_stamp column or store timezones, we can remove this, as its not a 100% fix. $rstc_obj = $rsc_obj->getRecurringScheduleTemplateControlObject(); if ( is_object( $rstc_obj ) ) { Debug::text( 'Recurring Schedule Template Control last updated by: ' . $rstc_obj->getUpdatedBy(), __FILE__, __LINE__, __METHOD__, 10 ); echo " Recurring Schedule Template Control ID: " . $rstc_obj->getID() . " Name: " . $rstc_obj->getName() . "\n"; if ( $rstc_obj->getUpdatedBy() > 0 ) { $ulf = TTnew( 'UserListFactory' ); $ulf->getById( $rstc_obj->getUpdatedBy() ); if ( $ulf->getRecordCount() > 0 ) { $ulf->getCurrent()->getUserPreferenceObject()->setTimeZonePreferences(); } else { //Use system timezone. TTDate::setTimeZone(); } } else { //Use system timezone. TTDate::setTimeZone(); } } //Make sure its always at least the display weeks based on the end of the current week. $maximum_end_date = ( ( TTDate::getEndWeekEpoch( $current_epoch ) + 1 ) + ( $rsc_obj->getDisplayWeeks() * ( 86400 * 7 ) ) - 1 ); if ( $rsc_obj->getEndDate() != '' && $maximum_end_date > $rsc_obj->getEndDate() ) { $maximum_end_date = $rsc_obj->getEndDate(); } Debug::text( 'Recurring Schedule ID: ' . $rsc_obj->getID() . ' Maximum End Date: ' . TTDate::getDate( 'DATE+TIME', $maximum_end_date ), __FILE__, __LINE__, __METHOD__, 10 ); $rsf = TTnew( 'RecurringScheduleFactory' ); $rslf = TTNew( 'RecurringScheduleListFactory' ); //Clear out recurring schedules for anything older than 1 week. $rsf->clearRecurringSchedulesFromRecurringScheduleControl( $rsc_obj->getID(), ( $current_epoch - ( 86400 * 720 ) ), $maximum_end_date ); $rsf->addRecurringSchedulesFromRecurringScheduleControl( $rsc_obj->getCompany(), $rsc_obj->getID(), TTDate::getBeginWeekEpoch( $current_epoch ), $maximum_end_date ); if ( $dry_run == true ) { $rsclf->FailTransaction(); } $rsclf->CommitTransaction(); } } } } } } echo "Done...\n"; Debug::WriteToLog(); //Debug::Display(); ?>