158 lines
6.8 KiB
PHP
Executable File
158 lines
6.8 KiB
PHP
Executable File
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class cron_maptoon extends CI_Controller {
|
|
#---------------------------------------------------------------------------
|
|
# PURPOSE : 실시간 맵툰 에피소드 조회 순위 등록
|
|
# CREATE : 2019-03-26
|
|
# 실행주기 : 1시간
|
|
#---------------------------------------------------------------------------
|
|
function maptoon_view_rank_update() {
|
|
if (!is_dir('./logs/cron_mt_ep_ranking/'.date("Ym"))) mkdir('./logs/cron_mt_ep_ranking/'.date("Ym"), 0777, TRUE); //log file 생성
|
|
$contents = 'log description';
|
|
# file helper
|
|
$this->load->helper('file');
|
|
$contents = '['.date("Y-m-d H:i:s").'] mt_ep_ranking_work start'.chr(10);
|
|
|
|
# model -create rank array
|
|
$this->load->database();
|
|
$num=0;
|
|
$_time=1;
|
|
$result;
|
|
while($num==0){
|
|
$result=$this->db->query("SELECT * FROM mt_ep_hit_log WHERE reg_date>=\"".date("Y-m-d H:i:s",strtotime ("-$_time hours"))."\" Order by ep_idx");
|
|
$num=$result->num_rows();
|
|
$_time++;
|
|
}
|
|
|
|
$row=$result->result_array();
|
|
|
|
$rank_list=array();
|
|
$y=0;
|
|
$ep_idx=0;
|
|
foreach($row as $val){
|
|
if($ep_idx!=$val['ep_idx']){
|
|
$ep_idx=$val['ep_idx'];
|
|
$y=0;
|
|
}
|
|
array_push($rank_list,$ep_idx);
|
|
}
|
|
$rank_list=array_count_values($rank_list);
|
|
arsort($rank_list); //ep_idx view count sort
|
|
|
|
$ep_idx_rank_list=array_keys($rank_list); // only ep_idx array;
|
|
|
|
$insert_date=array();
|
|
$rank=1;//순위
|
|
foreach($ep_idx_rank_list as $val){
|
|
array_push($insert_date,array('ep_idx'=>$val,'rank'=>$rank));
|
|
$rank++;
|
|
}
|
|
|
|
if(count($ep_idx_rank_list)<10){
|
|
$result=$this->db->query("SELECT * FROM mt_episodes ORDER BY reg_date DESC limit 10");
|
|
$row = $result->result_array();
|
|
foreach($row as $val){
|
|
$is_same=false;
|
|
foreach($ep_idx_rank_list as $val2){
|
|
if($val['idx']==$val2){
|
|
$is_same=true;
|
|
}
|
|
}
|
|
if(!$is_same){ array_push($insert_date,array('ep_idx'=>$val['idx'],'rank'=>$rank)); $rank++;}
|
|
if(count($insert_date)==10){break;}
|
|
}
|
|
};
|
|
|
|
print_r($row);
|
|
|
|
# insert_data;
|
|
$this->db->insert_batch("mt_ep_view_rank",$insert_date);
|
|
|
|
$contents.= date("Y-m-d H:i:s",strtotime ("-$_time hours")).' 업데이트 완료'.chr(10);
|
|
$contents.= '['.date("Y-m-d H:i:s").'] episode veiw count ranking end'.chr(10);
|
|
$contents.= '-------------------------------------------------------------------------------------'.chr(10);
|
|
write_file('./logs/cron_mt_ep_ranking/'.date("Ym").'/'.date("Ymd").'.php', $contents, 'a+');
|
|
|
|
}
|
|
|
|
#---------------------------------------------------------------------------
|
|
# PURPOSE : 예약 조회 후 업데이트
|
|
# CREATE : 2019-04-09
|
|
# 실행주기 : 매분
|
|
#---------------------------------------------------------------------------
|
|
function episode_reservation_update(){
|
|
if (!is_dir('./logs/cron_maptoon/'.date("Ym"))) mkdir('./logs/cron_maptoon/'.date("Ym"), 0777, TRUE); //log file 생성
|
|
$contents = 'log description';
|
|
# file helper
|
|
$this->load->helper('file');
|
|
$contents = '['.date("Y-m-d H:i:s").'] reservation_article_display_update start'.chr(10);
|
|
$num=0;
|
|
|
|
$this->load->model('maptoon/m_maptoon');
|
|
$result = $this->m_maptoon->get_epsiodes_reservation_list();
|
|
if(count($result)>0){
|
|
$num =$this->m_maptoon->episodes_is_display_update_batch($result);
|
|
}
|
|
|
|
$num>0?$contents.= $num.'개 업데이트-----------------------------------------------------------------------------'.chr(10):$contents.= '-----------------------------------------------------------------------------'.chr(10);
|
|
|
|
ob_flush();
|
|
flush();
|
|
sleep(1);
|
|
|
|
$contents.= '['.date("Y-m-d H:i:s").'] reservation_article_display_update end'.chr(10);
|
|
$contents.= '-------------------------------------------------------------------------------------'.chr(10);
|
|
write_file('./logs/cron_maptoon/'.date("Ym").'/'.date("Ymd").'.php', $contents, 'a+');
|
|
|
|
}
|
|
|
|
public function episode_in_category_update_caching() {
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL);
|
|
if (!is_dir('./logs/cron_maptoon/'.date("Ym"))) mkdir('./logs/cron_maptoon/'.date("Ym"), 0777, TRUE); //log file 생성
|
|
$contents = 'log description';
|
|
$this->load->helper('file');
|
|
$contents = '['.date("Y-m-d H:i:s").'] episode_in_category_update_caching start'.chr(10);
|
|
|
|
$this->load->database();
|
|
|
|
$query = "SELECT idx,mt_episodes_idx FROM mt_categories";
|
|
$result = $this->db->query($query);
|
|
foreach ($result->result_array() as $row){
|
|
$episodes_idx = explode(",",$row['mt_episodes_idx']);
|
|
$str = $row['mt_episodes_idx'];
|
|
$idx = $row['idx'];
|
|
|
|
$len = count($episodes_idx);
|
|
|
|
if(is_array($episodes_idx)==TRUE && is_numeric($idx)==TRUE
|
|
&& $idx>0 && $len>0) {
|
|
$this->load->model('maptoon/m_maptoon');
|
|
$ret = $this->m_maptoon->update_episodes_by_category($idx,$str);
|
|
|
|
$this->config->load('filecache',TRUE);
|
|
$file_cache_path = $this->config->item('file_cache_path','filecache');
|
|
$params = array('file_cache_path'=>$file_cache_path);
|
|
$this->load->library('maptoon_lib',$params);
|
|
|
|
// get episode data to write cache
|
|
$json_data = $this->m_maptoon->get_widget_info_by_episode_idx($episodes_idx,'json');
|
|
|
|
if($json_data!=FALSE) {
|
|
if($this->maptoon_lib->write_category_cache($idx,$json_data)) {
|
|
$contents.=$idx.'번 카테고리내 에피소드 등록이 완료되었습니다.'.chr(10);
|
|
}else {
|
|
$contents.=$idx.'번 카테고리내 에피소드 등록이 실패습니다.'.chr(10);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$contents.= '['.date("Y-m-d H:i:s").'] episode_in_category_update_caching end'.chr(10);
|
|
$contents.= '-------------------------------------------------------------------------------------'.chr(10);
|
|
write_file('./logs/cron_maptoon/'.date("Ym").'/caching'.date("Ymd").'.php', $contents, 'a+');
|
|
}
|
|
}
|
|
|
|
?>
|