lib/africompta/acaccess.rb in africompta-1.9.10 vs lib/africompta/acaccess.rb in africompta-1.9.11
- old
+ new
@@ -62,34 +62,10 @@
}
dputs(3) { "Found movements: #{ret.inspect}" }
ret
end
- def self.accounts_fetch_old(user)
- ret = ''
-
- Accounts.matches_by_account_id(0).to_a.concat(
- Accounts.matches_by_account_id(nil)).sort { |a, b|
- a.global_id <=> b.global_id }.each { |a|
- dputs(2) { "Found one root-account #{a.rev_index} - #{a.path_id}" }
- if a.global_id
- dputs(3) { "It's global" }
- a.get_tree { |acc|
- dputs(4) { "In get_tree #{acc.path_id}: #{acc.deleted == true} - #{acc.rev_index}" }
- if acc.rev_index > user.account_index
- dputs(4) { "Found account #{acc.name} with index #{acc.rev_index}" }
- ret += "#{acc.to_s}\n"
- end
- }
- else
- dputs(3) { "It's not global" }
- end
- dputs(3) { 'Will search for next' }
- }
- ret
- end
-
def self.accounts_fetch(user)
Accounts.data.select { |_k, v| v._rev_index > user.account_index }.
collect { |k, _v| Accounts.get_data_instance(k) }.
sort_by { |a| a.path }.
collect { |a| a.to_s }.
@@ -98,13 +74,13 @@
def self.get(p)
# Two cases:
# path/arg/user,pass - arg is used
# path/user,pass - arg is nil
- path, arg, id = p.split("/")
+ path, arg, id = p.split('/')
arg, id = id, arg if not id
- user, pass = id.split(",")
+ user, pass = id.split(',')
log_msg 'ACaccess.get', "get-merge-path #{path} - #{arg} with " +
"user #{user} and pass #{pass}"
u = Users.match_by_name(user)
u_local = Users.match_by_name('local')
@@ -118,65 +94,68 @@
# since the last update, again, do it from the root(s), else we have
# a problem for children without parents
ret = ''
dputs(2) { "user index is: #{u.account_index}" }
# Returns only one account
- if $1 == '_one'
- return Accounts.match_by_global_id(arg).to_s
+ case $1
+ when '_one'
+ return Accounts.match_by_global_id(arg).to_s
+ when '_all'
+ dputs(2) { 'Putting all accounts' }
+ ret = Accounts.search_all.collect { |acc|
+ dputs(4) { "Found account #{acc.name} with index #{acc.rev_index}" }
+ acc.to_s(true)
+ }.join("\n")
+ when '_count'
+ ret += Accounts.search_all.size.to_s
+ when '_part'
+ acc_start, acc_end = arg.split(',')
+ dputs(2) { "Putting accounts #{acc_start}..#{acc_end}" }
+ Accounts.search_all.select { |acc|
+ acc.rev_index >= acc_start.to_i and acc.rev_index <= acc_end.to_i
+ }.each { |acc|
+ dputs(4) { "Found account #{acc.name} with index #{acc.rev_index}" }
+ ret += "#{acc.to_s(true)}\n"
+ }
+ else
+ dputs(2) { 'Starting to search accounts' }
+ t = Time.now
+ ret += ACaccess.accounts_fetch(u)
+ dputs(2) { "Found #{ret.count("\n")} after #{Time.now - t} seconds" }
end
- if $1 == '_all'
- dputs(2) { 'Putting all accounts' }
- ret = Accounts.search_all.collect { |acc|
- dputs(4) { "Found account #{acc.name} with index #{acc.rev_index}" }
- acc.to_s(true)
- }.join("\n")
- elsif $1 == '_count'
- ret += Accounts.search_all.size.to_s
- elsif $1 == '_part'
- acc_start, acc_end = arg.split(",")
- dputs(2) { "Putting accounts #{acc_start}..#{acc_end}" }
- Accounts.search_all.select { |acc|
- acc.rev_index >= acc_start.to_i and acc.rev_index <= acc_end.to_i
- }.each { |acc|
- dputs(4) { "Found account #{acc.name} with index #{acc.rev_index}" }
- ret += "#{acc.to_s(true)}\n"
- }
- else
- dputs(2) { 'Starting to search accounts' }
- t = Time.now
- ret += ACaccess.accounts_fetch(u)
- dputs(2) { "Found #{ret.count("\n")} after #{Time.now - t} seconds" }
- end
dputs(3) { 'Finished search' }
return ret
-
# Gets all movements (for the accounts of that user)
when /movements_get(.*)/
dputs(2) { "movements_get#{$1} with #{arg.inspect}" }
start, stop = u.movement_index + 1, u_local.movement_index - 1
- # Returns only one account
- if $1 == '_one'
- return Movements.match_by_global_id(arg).to_s
- end
- if $1 == '_all_actual'
- start, stop = arg.split(/,/)
- ret = print_movements_actual(start, stop)
- else
- if $1 == '_all'
- start, stop = arg.split(/,/)
- end
- ret = print_movements(start, stop)
- end
+ ret = case $1
+ when '_one'
+ # Returns only one account
+ Movements.match_by_global_id(arg).to_s
+ when '_all_actual'
+ start, stop = arg.split(/,/)
+ print_movements_actual(start, stop)
+ when '_all'
+ Movements.search_all.collect { |m|
+ m.to_s
+ }.join("\n")
+ when '_range'
+ start, stop = arg.split(/,/)
+ print_movements(start, stop)
+ else
+ print_movements(start, stop)
+ end
dputs(2) { "Sending a total of #{ret.length}" }
dputs(3) { "Sending:\n #{ret.inspect}" }
return ret
when 'version'
return $VERSION.to_s
when 'index'
- return [u_local.account_index, u_local.movement_index].join(",")
+ return [u_local.account_index, u_local.movement_index].join(',')
when 'local_id'
return u_local.full
when 'reset_user_indexes'
@@ -194,15 +173,21 @@
while mov = Movements.match_by_global_id(arg)
dputs(3) { "Found movement #{mov.inspect}" }
mov.delete
end
dputs(3) { 'Finished deleting' }
+
+ when 'get_db'
+ Entities.save_all
+ return IO.read(Accounts.storage[:SQLiteAC].db_file)
end
+
return ''
end
def self.post(path, input)
+ #dputs_func
dputs(5) { "self.post with #{path} and #{input.inspect}" }
log_msg 'ACaccess.post', "post-merge-path #{path} with " +
"user #{input['user']} and pass #{input['pass']}"
user, pass = input['user'], input['pass']
u = Users.match_by_name(user)
@@ -229,11 +214,11 @@
if mov = Movements.from_json(m)
dputs(2) { "Saved movement #{mov.global_id}" }
else
dputs(0) { "Error: couldn't create movement from #{m.inspect}" }
end
- u.update_movement_index
+ u.update_movement_index unless input._debug
}
end
when 'movement_delete'
dputs(3) { 'Going to delete movement' }
while mov = Movements.match_by_global_id(input['global_id'])
@@ -242,16 +227,17 @@
end
dputs(3) { 'Finished deleting' }
when 'account_put'
dputs(3) { "Going to put account #{input['account'].inspect}" }
acc = Accounts.from_s(input['account'])
- u.update_account_index
+ u.update_account_index unless input._debug
dputs(2) { "Saved account #{acc.global_id}" }
when 'account_delete'
dputs(3) { 'Going to delete account' }
acc = Accounts.match_by_global_id(input['global_id'])
acc.delete(true)
end
return 'ok'
end
+
end