示例#1
0
function registerStage($registerInfo)
{
    global $wpdb;
    $wpdb->show_errors();
    $userLogin = wp_get_current_user()->user_login;
    $nowDateTime = getSqlNowDateTime();
    $stageId = 0;
    $results = array();
    $wpdb->query('START TRANSACTION');
    foreach ($registerInfo->stage_time as $stageTime) {
        $stageId = getStageId($registerInfo->stage_date, $stageTime);
        // リビジョンチェック
        $currentRevision = getCurrentRevision($stageId);
        if ($currentRevision != $registerInfo->revision) {
            $results[] = false;
            break;
        }
        $newRevision = $currentRevision + 1;
        // 公演の登録
        $results[] = $wpdb->insert('Stage', array('stage_id' => $stageId, 'revision' => $newRevision, 'program_id' => $registerInfo->stage_program, 'team_id' => $registerInfo->stage_team, 'stage_date' => $registerInfo->stage_date, 'stage_time' => $stageTime, 'is_shuffled' => $registerInfo->stage_shuffled, 'is_unofficial' => $registerInfo->stage_unofficial, 'regist_time' => $nowDateTime, 'regist_user' => $userLogin), array('%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s'));
        // 出演メンバー
        foreach ($registerInfo->stage_members as $memberId) {
            $results[] = $wpdb->insert('Stage_Member', array('stage_id' => $stageId, 'member_id' => $memberId, 'revision' => $newRevision, 'regist_time' => $nowDateTime, 'regist_user' => $userLogin), array('%d', '%d', '%d', '%s', '%s'));
        }
        // リンク
        foreach ($registerInfo->stage_links as $link) {
            $results[] = $wpdb->insert('Related_Link', array('stage_id' => $stageId, 'revision' => $newRevision, 'link' => $link, 'regist_time' => $nowDateTime, 'regist_user' => $userLogin), array('%d', '%d', '%s', '%s', '%s'));
        }
        // イベント
        $registerd_events = array();
        $registerd_event_members = array();
        foreach ($registerInfo->stage_events as $event) {
            $eventId = $event->event_id;
            if (!in_array($eventId, $registerd_events)) {
                $registerd_events[] = $eventId;
                $results[] = $wpdb->insert('Stage_Event', array('stage_id' => $stageId, 'event_id' => $eventId, 'revision' => $newRevision, 'regist_time' => $nowDateTime, 'regist_user' => $userLogin), array('%d', '%d', '%d', '%s', '%s'));
            }
            $memberId = $event->member_id;
            if (!in_array($eventId . "_" . $memberId, $registerd_event_members)) {
                $registerd_event_members[] = $eventId . "_" . $memberId;
                if ($memberId <= 0) {
                    continue;
                }
                $results[] = $wpdb->insert('Stage_Event_Member', array('stage_id' => $stageId, 'event_id' => $eventId, 'member_id' => $memberId, 'revision' => $newRevision, 'regist_time' => $nowDateTime, 'regist_user' => $userLogin), array('%d', '%d', '%d', '%d', '%s', '%s'));
            }
        }
        // コメント
        if ($registerInfo->stage_comment != "") {
            $results[] = $wpdb->insert('Stage_Comment', array('stage_id' => $stageId, 'branch_no' => 1, 'revision' => $newRevision, 'comment' => $registerInfo->stage_comment, 'regist_time' => $nowDateTime, 'regist_user' => $userLogin), array('%d', '%d', '%d', '%s', '%s', '%s'));
        }
    }
    $success = 1;
    foreach ($results as $result) {
        $success = $success * $result;
    }
    if ($success > 0) {
        $wpdb->query("COMMIT;");
    } else {
        $wpdb->query("ROLLBACK;");
        $stageId = 0;
    }
    return $stageId;
}
 /**
  * Checks for software updates and executes if there is a new revision
  * 
  */
 public function checkForUpdates()
 {
     $latest = getLatestRevision();
     if ($latest && ($latest != getCurrentRevision())) {
         dumpCache();
         setCurrentRevision($latest);
     }
 }