public function execRemove() { $sql = "SELECT user_id, followed_date, follower_count FROM dt_follower_cont WHERE account_id = ? AND following = 1 AND followed_date <= ? AND follower_count >= ? ORDER BY followed_date ASC"; $following_date = date("Y-m-d H:is", strtotime("-1 week")); $res = $this->DBobj->query($sql, array($this->Account_ID, $following_date, $this->LargeThanForrow_num)); if ($res and count($res)) { $remove_users = array(); for ($i = 0; $i < $this->MaxRemove_inDay and $i < count($res); $i++) { //リムーブ $option = array('user_id' => $res[$i]->user_id); $FriendshipsDestroy = new friendships_destroy($this->twObj); $api_res = $FriendshipsDestroy->setOption($option)->Request(); //エラーチェック リムーブできなくてもDBセット $apiErrorObj = new Api_Error($api_res); if ($apiErrorObj->error) { $mes = $apiErrorObj->errorMes_Str; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); } unset($apiErrorObj); $remove_users[] = $res[$i]->user_id; } //リムーブ情報DBセット $sql = "UPDATE dt_follower_cont SET following = 0, removing_date = now() WHERE account_id = ? AND user_id IN "; $sql .= "( " . implode(", ", $remove_users) . " )"; $removed_num = $this->DBobj->execute($sql, array($this->Account_ID)); $mes = $removed_num . "件 リムーブ処理実行\n"; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); $mes = implode(", ", $remove_users) . "\n"; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); } else { $mes = "0件 リムーブ処理実行\n"; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); } }
public function FollowingRemove() { //不具合が出ないよう設定調整 if ($this->Follow_Num_Inday > $this->Difference_Follow) { $this->Follow_Num_Inday = $this->Difference_Follow; } //リムーブしなくてはならない数 $must_remove_num = 0; //対象抽出 $sql = "SELECT user_id, following_date FROM dt_follower_cont WHERE account_id = ? AND following = 1 AND followed = 0 ORDER BY following_date ASC"; $res = $this->DBobj->query($sql, array($this->Account_ID)); if (!$res or !count($res)) { //リムーブする必要なし return; } //リムーブ必要数計算 $must_remove_num = count($res) + $this->Follow_Num_Inday - $this->Difference_Follow; if ($must_remove_num <= 0) { //リムーブする必要なし return; } //リムーブ数が妙に増大 if ($must_remove_num > $this->Follow_Num_Inday * 2) { $must_remove_num = $this->Follow_Num_Inday * 2; $mes = 'リムーブ数が増大しています。アカウントを確認してください。'; $sql = "INSERT INTO dt_message ( account_id, type, message1, check_flg, create_date) VALUES ( ?, ?, ?, 0, now())"; $in_count = $this->DBobj->execute($sql, array($this->Account_ID, $this->alert_mes_type, $mes)); //メール送信 $subject = 'アカウント:' . $this->AccountInfo->notice; Alert_Mail::sendAlertMail($this->alert_mail_add, $subject, $mes); } $remove_users = array(); for ($i = 0; $i < $must_remove_num and $i < count($res); $i++) { //リムーブ $option = array('user_id' => (string) $res[$i]->user_id); $FriendshipsDestroy = new friendships_destroy($this->twObj); $api_res = $FriendshipsDestroy->setOption($option)->Request(); //エラーチェック リムーブできなくてもDBセット $apiErrorObj = new Api_Error($api_res); if ($apiErrorObj->error) { $mes = $apiErrorObj->errorMes_Str; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); } unset($apiErrorObj); $remove_users[] = "'" . (string) $res[$i]->user_id . "'"; /////////////////// $mes = "user_id:" . (string) $res[$i]->user_id . "\n"; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); ////////////////// } /////////////////// $mes = "remove_users:" . print_r($remove_users, true) . "\n"; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); $mes = "フォロワー差分数:" . (string) count($res) . "\n"; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); ////////////////// //リムーブ情報DBセット $sql = "UPDATE dt_follower_cont SET following = 0, removing_date = now() WHERE account_id = ? AND user_id IN "; $sql .= "( " . implode(", ", $remove_users) . " )"; $removed_num = $this->DBobj->execute($sql, array($this->Account_ID)); $mes = date("Y-m-d H:i:s") . " リムーブ実行件数 " . $must_remove_num . "件\n"; $mes .= date("Y-m-d H:i:s") . " リムーブ成功件数 " . $removed_num . "件\n"; error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile); }