]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/wordpress.py
Utilize new fields in installer script for Wordpress 3.0.
[wizard.git] / wizard / app / wordpress.py
index 546827fa53e4b9ae6376fdf89bcee04da7ec9b6a..add10ff9105690f2869933ad8f06c6d9aa6ecc40 100644 (file)
@@ -4,6 +4,7 @@ import logging
 import distutils
 import urlparse
 import hashlib
+import sqlalchemy.exc
 
 from wizard import app, install, resolve, sql, util
 from wizard.app import php
@@ -35,21 +36,23 @@ class Application(app.Application):
     install_schema = install.ArgSchema("db", "admin", "email", "title")
     deprecated_keys = set(['WIZARD_SECRETKEY'])
     random_keys = set(['WIZARD_SECRETKEY', 'WIZARD_AUTH_KEY', 'WIZARD_SECURE_AUTH_KEY', 'WIZARD_LOGGED_IN_KEY', 'WIZARD_NONCE_KEY'])
+    random_blacklist = set(['put your unique phrase here'])
+    def urlFromExtract(self, deployment):
+        try:
+            meta = sql.connect(deployment.dsn)
+            wp_options = meta.tables["wp_options"]
+            query = wp_options.select(wp_options.c.option_name == 'home')
+            return query.execute().fetchone()['option_value']
+        except sqlalchemy.exc.OperationalError:
+            return None
     def download(self, version):
         return "http://wordpress.org/wordpress-%s.tar.gz" % version
     def checkConfig(self, deployment):
         return os.path.isfile("wp-config.php")
     def checkWeb(self, deployment):
-        # XXX: this sucks pretty hard
-        def doCheck():
-            return self.checkWebPage(deployment, "",
-                    outputs=["<html", "WordPress", "feed"],
-                    exclude=["Error establishing a database connection"])
-        if not doCheck():
-            deployment.enableOldStyleUrls()
-            return doCheck()
-        else:
-            return True
+        return self.checkWebPage(deployment, "",
+                outputs=["<html", "WordPress", "feed"],
+                exclude=["Error establishing a database connection"])
     def detectVersion(self, deployment):
         return self.detectVersionFromFile("wp-includes/version.php", php.re_var("wp_version"))
     def install(self, version, options):
@@ -69,6 +72,10 @@ class Application(app.Application):
                 'admin_email': options.email,
                 'submit': 'Continue',
                 'step': '2',
+                # Version >= 3.0
+                'user_name': options.admin_name,
+                'admin_password': options.admin_password,
+                'admin_password2': options.admin_password,
                 }
         old_mode = os.stat(".").st_mode
         os.chmod(".", 0777) # XXX: squick squick
@@ -95,19 +102,29 @@ class Application(app.Application):
         wp_options = meta.tables["wp_options"]
         wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
         wp_options.update().where(wp_options.c.option_name == 'home').values(option_value="http://%s%s" % (options.web_host, options.web_path)).execute() # XXX: what if missing leading slash; this should be put in a function
-        # should also set the username and admin password
 
-        wp_users = meta.tables["wp_users"]
-        hashed_pass = hashlib.md5(options.admin_password).hexdigest()
-        wp_users.update().where(wp_users.c.ID == 1).values(user_login=options.admin_name,user_nicename=options.admin_name,display_name=options.admin_name,user_pass=hashed_pass).execute()
-        wp_usermeta = meta.tables["wp_usermeta"]
-        wp_usermeta.delete().where(wp_usermeta.c.user_id==1 and wp_usermeta.c.meta_key == "default_password_nag").execute()
+        if version < distutils.version.LooseVersion("3.0"):
+            wp_users = meta.tables["wp_users"]
+            hashed_pass = hashlib.md5(options.admin_password).hexdigest()
+            wp_users.update().where(wp_users.c.ID == 1).values(user_login=options.admin_name,user_nicename=options.admin_name,display_name=options.admin_name,user_pass=hashed_pass).execute()
+            wp_usermeta = meta.tables["wp_usermeta"]
+            wp_usermeta.delete().where(wp_usermeta.c.user_id==1 and wp_usermeta.c.meta_key == "default_password_nag").execute()
 
         # now we can restore the wp_mail function in wp-includes/pluggable[-functions].php
         pluggable_file = open(pluggable_path,'w')
         pluggable_file.write(pluggable)
         pluggable_file.close()
 
+        # replace random variable stubs with real values
+        old_config = open('wp-config.php').read()
+        def replace_with_random(s):
+            return s.replace('put your unique phrase here', util.random_key(), 1)
+        config = replace_with_random(old_config)
+        while config != old_config:
+            old_config = config
+            config = replace_with_random(config)
+        open('wp-config.php', 'w').write(config)
+
         php.ini_replace_vars()
     def upgrade(self, d, version, options):
         result = d.fetch("wp-admin/upgrade.php?step=1")