示例#1
0
 private function addCronJob($startDate)
 {
     $cronDate = $this->cronDateTime($startDate);
     $cron = new Crontab('nymedia_crontab');
     $cron->addApplicationJob('yiiccmd', 'Nymedia holiday', array(), $cronDate['minute'], $cronDate['hour'], $cronDate['day'], $cronDate['month'], '*');
     $cron->saveCronFile();
     // save to my_crontab cronfile
     $cron->saveToCrontab();
     // adds all my_crontab jobs to system (replacing previous my_crontab jobs)
 }
	/**
	 * Updates a particular model.
	 * If update is successful, the browser will be redirected to the 'view' page.
	 * @param integer $id the ID of the model to be updated
	 */
	public function actionUpdate($id)
	{
		$model=$this->loadModel($id);

		// comment the following line if AJAX validation is not needed
		 $this->performAjaxValidation($model);

		if(isset($_POST['ScheduleTiming']))
		{
			$model->attributes=$_POST['ScheduleTiming'];
			if($model->schedule_timing_minute==60)
			{
			  $minute="*";
			}
			else
			{
			  $minute=$model->schedule_timing_minute;
			}
			if($model->schedule_timing_hour==24)
			{
			  $hour="*";
			}
			else
			{
		          $hour=$model->schedule_timing_hour;
			}
			if($model->schedule_timing_date==32)
			{
				$date="*";
			}
			else
			{
				$date=$model->schedule_timing_date;
			}
			$days=array("Sunday"=>7,"Monday"=>1,"Tuesday"=>2,"Wednesday"=>3,"Thursday"=>4,"Friday"=>5,"Saturday"=>6,"*"=>"*");
			$day=$days[$model->schedule_timing_day];
			$months=array('January'=>1,'February'=>2,'March'=>3,'April'=>4,'May'=>5,'June'=>6,'July'=>7,'August'=>8,'September'=>9,'October'=>10,'November'=>11,'December'=>12,'*'=>'*');
			$month=$months[$model->schedule_timing_month];
		
			$model->schedule_timing_name=$minute."-".$hour."-".$date."-".$model->schedule_timing_month."-".$model->schedule_timing_day;
			if($model->save())
			{
			$crons=StudentSmsEmailDetails::model()->findAll(array('condition'=>'student_sms_email_details_schedule_time_id='.$model->schedule_timing_id));
			$j = count($crons);
			$i = 0;

			foreach($crons as $cron)
			{
			    if($cron->student_sms_email_details_purpose=="fees")
			    {
				$period=$cron->academic_period_id;
				$sem=$cron->academic_name_id;
				$branch=$cron->branch_id;
				$div=$cron->division_id;
				$purpose=$cron->student_sms_email_details_purpose;
				$message=$cron->message_email_text;
				$user=$cron->created_by;
				$to=$cron->student_sms_email_details_fees_msg_type;
				$mobile=$cron->student_sms_email_details_to_mobile;
				$cronid=$cron->student_sms_email_details_cron_no-$i;
				$mycron = new Crontab('my_crontab'); 
				$jobs_obj = $mycron->getJobs();	
				$mycron->removeJob($cronid); 	
				$mycron->saveCronFile(); 	
				$mycron->saveToCrontab();
				StudentSmsEmailDetails::model()->updateCounters(array('student_sms_email_details_cron_no'=>-1),'student_sms_email_details_cron_no>'.$cronid);
				$mycron = new Crontab('my_crontab'); 
				$cron->student_sms_email_details_cron_no=((count($mycron->getJobs())));
				$cron->save();
				$mycron->addJob(Yii::getPathOfAlias('webroot').'/protected/yiic feesschedulesms '.$period." ".$sem." ".$branch." ".$div." ".$purpose." \"$message\" ".$user." ".$to." ".$mobile , $minute, $hour,$date,$month,$day);
				$mycron->saveCronFile(); 	
				$mycron->saveToCrontab();
			     }
			     else
			     {
				$period=$cron->academic_period_id;
				$sem=$cron->academic_name_id;
				$branch=$cron->branch_id;
				$div=$cron->division_id;
				$purpose=$cron->student_sms_email_details_purpose;
				$user=$cron->created_by;
				$mobile=$cron->student_sms_email_details_to_mobile;
				$cronid=$cron->student_sms_email_details_cron_no-$i;
				$mycron = new Crontab('my_crontab'); 
				$jobs_obj = $mycron->getJobs();	
				$mycron->removeJob($cronid); 	
				$mycron->saveCronFile(); 	
				$mycron->saveToCrontab();
				StudentSmsEmailDetails::model()->updateCounters(array('student_sms_email_details_cron_no'=>-1),'student_sms_email_details_cron_no>'.$cronid);
				$mycron = new Crontab('my_crontab'); 
				$cron->student_sms_email_details_cron_no=(count($mycron->getJobs()));
				$cron->save();
				$mycron->addJob(Yii::getPathOfAlias('webroot').'/protected/yiic attendance '.$period." ".$sem." ".$branch." ".$div." ".$purpose." ".$user." ".$mobile,$minute,$hour,$date,$month,$day);
				$mycron->saveCronFile(); 	
				$mycron->saveToCrontab();
			      }
			$i++;	
			}
			$backup_crons=DatabaseBackupCron::model()->findAll(array('condition'=>'database_backup_cron_schedule_time_id='.$model->schedule_timing_id));
			$j = count($backup_crons);
			$i = 0;

			foreach($backup_crons as $cron)
			{
				$cronid=$cron->database_backup_cron_no-$i;
				$mycron = new Crontab('backup_crontab'); 
				$jobs_obj = $mycron->getJobs();	
				$mycron->removeJob($cronid); 	
				$mycron->saveCronFile(); 	
				$mycron->saveToCrontab();
				DatabaseBackupCron::model()->updateCounters(array('database_backup_cron_no'=>-1),'database_backup_cron_no>'.$cronid);
				$mycron = new Crontab('backup_crontab'); 
				$cron->database_backup_cron_no=((count($mycron->getJobs())));
				$cron->save();
				$mycron->addJob(Yii::getPathOfAlias('webroot').'/protected/yiic backup' , $minute, $hour,$date,$month,$day);	
				$mycron->saveCronFile(); 	
				$mycron->saveToCrontab();
				$i++;	
			}
			
				$this->redirect(array('view','id'=>$model->schedule_timing_id));
			}
		}
		$this->render('update',array(
			'model'=>$model,
		));
	}
	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		$model=$this->loadModel($id);
		$cron = new Crontab('backup_crontab'); 
		$jobs_obj = $cron->getJobs();	
		$cron->removeJob($model->database_backup_cron_no); 			
		$cron->saveCronFile(); 	
		$cron->saveToCrontab();	
		$cronid=$model->database_backup_cron_no;
		DatabaseBackupCron::model()->updateCounters(array('database_backup_cron_no'=>-1),'database_backup_cron_no>'.$cronid);

		// we only allow deletion via POST request
		$this->loadModel($id)->delete();

		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
		if(!isset($_GET['ajax']))
	 	  $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
	}
	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		$model=$this->loadModel($id);
		$cron = new Crontab('my_crontab'); 
		$jobs_obj = $cron->getJobs();	
		$cron->removeJob($model->student_sms_email_details_cron_no); 			
		$cron->saveCronFile(); 	
		$cron->saveToCrontab();	
		$cronid=$model->student_sms_email_details_cron_no;
		StudentSmsEmailDetails::model()->updateCounters(array('student_sms_email_details_cron_no'=>-1),'student_sms_email_details_cron_no>'.$cronid);
		$this->loadModel($id)->delete();
		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
		if(!isset($_GET['ajax']))
			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('scheduleMessages'));
	}
	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		if(Yii::app()->request->isPostRequest)
		{
			// we only allow deletion via POST request
			// we only allow deletion via POST request
			$model=$this->loadModel($id);
			$cron = new Crontab('mail_crontab'); 
			$jobs_obj = $cron->getJobs();	
			$cron->removeJob($model->student_attendence_email_cron_no); 				$cron->saveCronFile(); 	
			$cron->saveToCrontab();	
			$cronid=$model->student_attendence_email_cron_no;
			StudentAttendenceEmail::model()->updateCounters(array('student_attendence_email_cron_no'=>-1),'student_attendence_email_cron_no>'.$cronid);
			$this->loadModel($id)->delete();

			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
			if(!isset($_GET['ajax']))
				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
		}
		else
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
	}