-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypo3.rb
51 lines (41 loc) · 1.45 KB
/
typo3.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Typo3
attr_reader :sitename,:username, :password, :host, :dbname, :install_password
def initialize
get_TYPO3_details
# look at somehow making this more automatically specific to environment
@port = 3306
@socket = `locate -l 1 mysql.sock`.to_s.strip
end
def show_config
config = %{
TYPO3 Sitename: #{@sitename}
DB Username: #{@username}
DB Password: #{@password}
DB Host: #{@host}
DB Name: #{@dbname}
Install Tool: #{@install_password}
}
print config
end
def with_db
dbh = Mysql.real_connect(self.host,self.username,self.password,self.dbname,@port,@socket)
begin
yield dbh
ensure
dbh.close
end
end
private
def get_TYPO3_details
localconf = FileList['**/localconf.php']
localconf.each do |t|
conf = IO.read(t)
@sitename = conf.scan(/\$TYPO3_CONF_VARS\[\'SYS\'\]\[\'sitename\'\]\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
@username = conf.scan(/\$typo_db_username\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
@password = conf.scan(/\$typo_db_password\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
@host = conf.scan(/\$typo_db_host\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
@dbname = conf.scan(/\$typo_db\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
@install_password = conf.scan(/\$TYPO3_CONF_VARS\[\'BE\'\]\[\'installToolPassword\'\]\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
end
end
end