/** * 检查是否需要保存快照 * @param int $user_id 用户ID * @param string $operation 操作说明 * @param bool $auto 是否自动保存快照 * @param bool $save 是否保存 ($auto == FALSE时生效) * @return bool */ public function is_save_snapshot($user_id, $operation, $auto = TRUE, $save = FALSE) { //联系人为空 $result = FALSE; $history = $this->contact_mapper->get_last_history($user_id); if ($auto == TRUE) { if ($operation == 'recover_snapshot') { $result = TRUE; } else { //粒度不分太细 switch (TRUE) { //操作历史为空 case $history === FALSE: //上次操作应用不同 //上次操作应用不同 case $history['appid'] != $this->appid: //上次操作设备不同 //上次操作设备不同 case $history['device_id'] != $this->device_id: //上次操作说明不同 //上次操作说明不同 case $history['operation'] != $operation: //上次操作与本次操作时间超过10分钟 //上次操作与本次操作时间超过10分钟 case api::get_now_time() - $history['dateline'] > 600: $result = TRUE; break; //操作为合并操作 //操作为合并操作 case $operation === 'merge': $deleted_ids = unserialize($history['deleted_ids']); if (!empty($deleted_ids)) { $result = TRUE; } break; default: $result = FALSE; break; } } $this->is_snapshot = api::get_now_time() == $history['dateline'] ? FALSE : $result; $this->is_history = $result; } else { //根据设定参数备份快照 if ($save == TRUE) { $this->is_snapshot = TRUE; $this->is_history = TRUE; } else { $this->is_snapshot = FALSE; $this->is_history = FALSE; } } $this->history = $history; $this->operation = $operation; if ($this->is_snapshot) { $this->count = $this->contact_mapper->get_count($user_id); $this->category_count = $this->contact_mapper->get_category_count($user_id); } if ($operation == 'add') { $this->count = isset($this->count) ? $this->count : $this->contact_mapper->get_count($user_id); if ($this->count == 0) { $this->is_snapshot = FALSE; } else { $this->category_count = $this->contact_mapper->get_category_count($user_id); } } }