} } } echo "Starting: " . strftime('%Y-%m-%d %H:%M %Z') . "\n"; for ($i = 1; $i < $argc; $i++) { if ($argv[$i] == "--test") { $test = true; } else { if ($argv[$i] == "--days") { $days = $argv[++$i]; } else { if ($argv[$i] == "--list") { delete_list($argv[++$i]); } else { if ($argv[$i] == "--profiles") { delete_profiles(); } else { if ($argv[$i] == "--forums") { delete_forums(); } else { if ($argv[$i] == "--id_range") { $id1 = $argv[++$i]; $id2 = $argv[++$i]; if (!is_numeric($id1) || !is_numeric($id2)) { die("bad args\n"); } if ($id2 < $id1) { die("bad args\n"); } for ($i = $id1; $i <= $id2; $i++) { $user = BoincUser::lookup_id($i);
/** * ユーザの削除 * * @param array $queries * @param array $options * * @return resource */ function delete_users($queries, $options = array()) { $queries = db_placeholder($queries); $options = array('softdelete' => isset($options['softdelete']) ? $options['softdelete'] : true, 'associate' => isset($options['associate']) ? $options['associate'] : false); // 削除するデータのIDを取得 $users = db_select(array('select' => 'id', 'from' => DATABASE_PREFIX . 'users AS users', 'where' => isset($queries['where']) ? $queries['where'] : '', 'limit' => isset($queries['limit']) ? $queries['limit'] : '')); $deletes = array(); foreach ($users as $user) { $deletes[] = intval($user['id']); } if ($options['associate'] === true) { // 関連するデータを削除 $resource = delete_profiles(array('where' => 'user_id IN(' . implode($deletes) . ')')); if (!$resource) { return $resource; } } if ($options['softdelete'] === true) { // データを編集 $resource = db_update(array('update' => DATABASE_PREFIX . 'users AS users', 'set' => array('deleted' => localdate('Y-m-d H:i:s'), 'username' => array('CONCAT(\'DELETED ' . localdate('YmdHis') . ' \', username)'), 'email' => array('CONCAT(\'DELETED ' . localdate('YmdHis') . ' \', email)')), 'where' => isset($queries['where']) ? $queries['where'] : '', 'limit' => isset($queries['limit']) ? $queries['limit'] : '')); } else { // データを削除 $resource = db_delete(array('delete_from' => DATABASE_PREFIX . 'users AS users', 'where' => isset($queries['where']) ? $queries['where'] : '', 'limit' => isset($queries['limit']) ? $queries['limit'] : '')); } return $resource; }