Created
November 6, 2012 07:42
-
-
Save ssaadh/4023280 to your computer and use it in GitHub Desktop.
Using Owncloud with files mounted outside data folder. Owncloud didn't set correct parent for 1st account that had files added into the file cache table, fscache, in Mysql or Sqlite. Quickly made this hack. Heh, go through more than ~1000 rows and this wi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require 'sqlite3' | |
require 'mysql2' | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'mysql2', | |
:host => 'localhost', | |
:username => 'USERNAME', | |
:password => 'PASSWORD', | |
:database => 'DATABASE_NAME' | |
) | |
class Owncloud < ActiveRecord::Base | |
self.table_name = 'oc_fscache' | |
end | |
#table_name = 'oc_fscache' | |
require 'benchmark' | |
total_time = 0 | |
#The ids of the rows in the fscache table | |
( 1000..2000 ).each do | i | | |
seconds = Benchmark.realtime do | |
single_row = Owncloud.find_by_id( i ) | |
if single_row.nil? || single_row.parent != -1 | |
next | |
end | |
@find_parent_directory = Owncloud.find( :first, :conditions => [ 'user = ? AND parent != ? AND path = ?', 'skinnymuch', '-1', File.dirname( single_row.path ) ] ) | |
if !@find_parent_directory.nil? | |
#ActiveRecord::Base.connection.execute( "UPDATE #{table_name} SET parent='#{@find_parent_directory.id}' WHERE id='#{single_row.id}'" ) | |
single_row.update_column( 'parent', @find_parent_directory.id ) | |
end | |
end | |
total_time += seconds | |
end | |
puts total_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment