Skip to content

Commit

Permalink
add Typo3 class as library and add new command for showing current si…
Browse files Browse the repository at this point in the history
…te configuration
  • Loading branch information
andyh committed Jan 26, 2009
1 parent 01445dd commit 614f0f0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
27 changes: 25 additions & 2 deletions bin/typo3
Expand Up @@ -2,9 +2,12 @@

require "fileutils"
require "rubygems"
require "rake"
require "mysql"
require "thor"
require "open-uri"
require "yaml"
require "typo3"

class TYPO3Installer < Thor

Expand All @@ -13,10 +16,30 @@ class TYPO3Installer < Thor

end

desc "config", "show current site config"
def config
if current_directory_is_typo3_install?
t3site = Typo3.new
t3site.show_config
else
abort 'Not a TYPO3 Installation'
end
end

private
def current_directory_is_typo3_install?
local_typo3_structure = ["fileadmin","typo3conf","typo3temp","uploads"]
if (Dir.glob('*').find_all {|f| local_typo3_structure.include?(f) }).size == 4
true
else
false
end
end

def typo3_locations
{ :official => 'http://sourceforge.net/project/showfiles.php?group_id=20391&package_id=14557',
:local => '/usr/local/typo3/',
{ :official => 'http://sourceforge.net/project/showfiles.php?group_id=20391&package_id=14557',
:heanet_mirror => 'http://heanet.dl.sourceforge.net/sourceforge/typo3/',
:local => '/usr/local/typo3/',
}
end

Expand Down
51 changes: 51 additions & 0 deletions lib/typo3.rb
@@ -0,0 +1,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

0 comments on commit 614f0f0

Please sign in to comment.