<?php if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

use GO\Scheduler;
use Aws\S3\S3Client;

class Schedule extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        // if (!$this->input->is_cli_request()) {
        //     echo 'Not allowed';
        //     exit();
        // }
    }

    public function index()
    {
        // Create a new scheduler
        $scheduler = new Scheduler();

        // ... configure the scheduled jobs (see below) ...

        // Let the scheduler execute jobs which are due.
        $scheduler->run();
    }

    public function aws() {
        $this->load->database();
        $query = $this->db->limit(1)->get('cm_post')->order_by('datePosted', 'desc')->result();

        $s3 = new S3Client([
            'version' => 'latest',
            'region'  => 'ap-northeast-2',
            'credentials' => [
				'key'    => "AKIA2WGASVZ56VOBTZJE",
				'secret' => "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",
			]
        ]);

        $result = $s3->putObject([
			'Bucket' => 'elasticbeanstalk-ap-northeast-2-734843285115',
			'Key'    => $file_name,
            'SourceFile' => BASEPATH	,
            'ACL'    => 'public-read'		
		]);

		var_dump($result);
    }
}
