Skip to content
Snippets Groups Projects
Commit e4d28d8a authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Merge branch 'master' into portal_update

parents fcd1c767 e970f9a2
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@ module Paginator
def offset
return params[:offset].to_i if !params[:offset].blank?
return params[:page].to_i*params[:results_per_page].to_i if !params[:page].blank? && !params[:results_per_page].blank?
return params[:page].to_i*limit if !params[:page].blank?
return 0
end
......
......@@ -29,7 +29,7 @@ module ReviewableController
# GET /v1/collections/1/reviews
def index
render json: Review.where(reviewable: reviewable)
render json: paginate(Review.where(reviewable: reviewable)), each_serializer: ReviewSerializer
end
# GET /v1/collections/1/reviews/1
......
......@@ -20,13 +20,14 @@
class V1::ReviewsController < ApplicationController
include ::DeletedObjectsController
include ::ResourceModel
include ::Paginator
before_action :set_review, only: [:show, :destroy, :rate, :update]
before_action :authenticate_user!, only: [:create, :rate, :destroy, :update]
# GET /v1/collections/1/reviews
def index
render json: reviewable.reviews, each_serializer: ReviewSerializer
render json: paginate(reviewable.reviews), each_serializer: ReviewSerializer
end
# GET /v1/collections/1/reviews/1
......
......@@ -38,6 +38,64 @@ require 'fileutils'
end
end
task check_links: :environment do
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
start = 1
finish = 999
batch_size = 1000
last_id = LearningObject::Attachment.count > 0 ? LearningObject::Attachment.last.id : 0
loop do
begin
p "start: #{start}, finish: #{finish}"
LearningObject::Attachment.find_each(start: start, finish: finish) do |att|
att_url = att.retrieve_url
if att_url.blank?
p "-----------------------------------------------------"
p "Retrieve URL nil"
p "LearningObject id: #{att.learning_object.id}" if !att.learning_object.nil?
p "Attachment id: #{att.id}, id_dspace: #{att.id_dspace}"
else
begin
URI.parse(att_url)
rescue URI::InvalidURIError
p "-----------------------------------------------------"
p "Invalid URI: #{att_url}"
p "LearningObject id: #{att.learning_object.id}" if !att.learning_object.nil?
p "Attachment id: #{att.id}, id_dspace: #{att.id_dspace}"
next
end
uri = URI(att_url)
response = Net::HTTP.get_response(uri)
if !response.kind_of? Net::HTTPSuccess
p "-----------------------------------------------------"
p "Response != 200: #{response.inspect}"
p "Link: #{att_url}"
p "LearningObject id: #{att.learning_object.id}" if !att.learning_object.nil?
p "Attachment id: #{att.id}, id_dspace: #{att.id_dspace}"
end
end
end
rescue Exception => e
#logger.warn 'Database error, going to sleep'
p 'Database error, going to sleep'
#logger.error e
p e
p e.class
p e.message
ActiveRecord::Base.clear_active_connections!
# Sleeps for a while to wait database's recovery
sleep(60.seconds)
# Goes to next iteration to retry
next
else
start += batch_size - 1
finish += batch_size
break if start >= last_id
end
end
end
private
def dir_size(dir)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment