<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class WeeklyBackup { 

    private $CI = null;

	public $error = '';

	public function __construct()
	{
		$this->CI = &get_instance();
		$this->error = '';
	}

    public function trigger($job)
	{
		
		if (!$job)
		{
			return;
		}
		if(empty($job["actConfig"])) {
            return;
        }
        $config = JSON_decode($job['actConfig'],true);
        if(empty($config['weeklybackup'])) {
            return;
        }
		$this->CI->load->model('UpdateModel');
       	$this->CI->UpdateModel->ob_dumpDB(1,'W');
        return true;
	}

	private function error_log($log) {
		$this->CI->load->helper('file');
        $file_path = 'temp'.DS.'cron'.DS.'WeeklyBackup'.DS.$log['cId'];

        if(!is_dir($file_path))
        {
            mkdir($file_path, 0755, TRUE);
		}
		
		$output ="=====================".base_url(uri_string())."=====================\n";
		$output.=$log['error']."\n";
		if ( ! write_file(FCPATH  . $file_path."/log.txt", $output, 'a+')){
            log_message('debug','Unable to write query the file');
        }
	}
}