Esempio n. 1
0
 def drupal_updatedb(self):
     self.log.info('Initiated Updatedb.')
     try:
         alias = '@%s_%s' % (self.project, self.update_env)
         result = drupaltools.updatedb(alias)
     except:
         self.log.exception('Updatedb encountered a fatal error.')
         raise
     else:
         self.log.info('Updatedb complete.')
         pantheon.log_drush_backend(result, self.log)
Esempio n. 2
0
 def drupal_updatedb(self):
     self.log.info('Initiated Updatedb.')
     try:
         alias = '@%s_%s' % (self.project, self.update_env)
         result = drupaltools.updatedb(alias)
     except:
         self.log.exception('Updatedb encountered a fatal error.')
         raise
     else:
         self.log.info('Updatedb complete.')
         pantheon.log_drush_backend(result, self.log)
Esempio n. 3
0
    def enable_pantheon_settings(self):
        """Enable required modules, and set Pantheon defaults.

        """
        if self.version == 6:
            required_modules = ['apachesolr',
                                'apachesolr_search',
                                'locale',
                                'pantheon_api',
                                'pantheon_login',
                                'syslog',
                                'varnish']
        elif self.version == 7:
            required_modules = ['apachesolr',
                                'apachesolr_search',
                                'syslog',
                                'pantheon_api',
                                'pantheon_login',
                                'pantheon_apachesolr']

        # Enable modules.
        with settings(hide('warnings'), warn_only=True):
            for module in required_modules:
                result = local('drush -by @working_dir en %s' % module)
                pantheon.log_drush_backend(result, self.log)
                if result.failed:
                    # If importing vanilla drupal, this module wont exist.
                    if module != 'cookie_cache_bypass':
                        message = 'Could not enable %s module.' % module
                        self.log.warning('%s\n%s' % (message, result.stderr))
                        postback.build_warning(message)
                        print message
                        print '\n%s module could not be enabled. ' % module + \
                              'Error Message:'
                        print '\n%s' % result.stderr
                else:
                    self.log.info('%s enabled.' % module)

        if self.version == 6:
            drupal_vars = {
                'apachesolr_search_make_default': 1,
                'apachesolr_search_spellcheck': 1,
                'cache': '3',
                'block_cache': '1',
                'page_cache_max_age': '900',
                'page_compression': '0',
                'preprocess_js': '1',
                'preprocess_css': '1'}

        elif self.version == 7:
            drupal_vars = {
                'cache': 1,
                'block_cache': 1,
                'cache_lifetime': "0",
                'page_cache_maximum_age': "900",
                'page_compression': 0,
                'preprocess_css': 1,
                'preprocess_js': 1,
                'search_active_modules': {
                    'apachesolr_search':'apachesolr_search',
                    'user': '******',
                    'node': 0},
                'search_default_module': 'apachesolr_search'}

        # Set variables.
        (db_username, db_password, db_name) = pantheon.get_database_vars(self, 'dev')
        db = dbtools.MySQLConn(database = db_name,
                               username = db_username,
                               password = db_password)
        for key, value in drupal_vars.iteritems():
            db.vset(key, value)

        # apachesolr module for drupal 7 stores config in db.
        # TODO: use drush/drupal api to do this work.
        try:
            if self.version == 7:
                db.execute('TRUNCATE apachesolr_environment')
                for env in self.environments:
                    config = self.config['environments'][env]['solr']

                    env_id = '%s_%s' % (self.project, env)
                    name = '%s %s' % (self.project, env)
                    url = 'http://%s:%s%s' % (config['solr_host'],
                                              config['solr_port'],
                                              config['solr_path'])

                    # Populate the solr environments
                    db.execute('INSERT INTO apachesolr_environment ' + \
                        '(env_id, name, url) VALUES ' + \
                        '("%s", "%s", "%s")' % (env_id, name, url))

                    # Populate the solr environment variables
                    db.execute('INSERT INTO apachesolr_environment_variable '+\
                               '(env_id, name, value) VALUES ' + \
                               "('%s','apachesolr_read_only','s:1:\"0\"')" % (
                                                                      env_id))
        except Exception as mysql_error:
             self.log.error('Auto-configuration of ApacheSolr module failed: %s' % mysql_error)
             pass

        db.close()

        # D7: apachesolr config link will not display until cache cleared?
        with settings(warn_only=True):
            result = local('drush @working_dir -y cc all')
            pantheon.log_drush_backend(result, self.log)

        # Run updatedb
        drupaltools.updatedb(alias='@working_dir')

        # Remove temporary working_dir drush alias.
        alias_file = '/opt/drush/aliases/working_dir.alias.drushrc.php'
        if os.path.exists(alias_file):
            local('rm -f %s' % alias_file)
Esempio n. 4
0
    def enable_pantheon_settings(self):
        """Enable required modules, and set Pantheon defaults.

        """
        if self.version == 6:
            required_modules = [
                'apachesolr', 'apachesolr_search', 'locale', 'pantheon_api',
                'pantheon_login', 'syslog', 'varnish'
            ]
        elif self.version == 7:
            required_modules = [
                'apachesolr', 'apachesolr_search', 'syslog', 'pantheon_api',
                'pantheon_login', 'pantheon_apachesolr'
            ]

        # Enable modules.
        with settings(hide('warnings'), warn_only=True):
            for module in required_modules:
                result = local('drush -by @working_dir en %s' % module)
                pantheon.log_drush_backend(result, self.log)
                if result.failed:
                    # If importing vanilla drupal, this module wont exist.
                    if module != 'cookie_cache_bypass':
                        message = 'Could not enable %s module.' % module
                        self.log.warning('%s\n%s' % (message, result.stderr))
                        postback.build_warning(message)
                        print message
                        print '\n%s module could not be enabled. ' % module + \
                              'Error Message:'
                        print '\n%s' % result.stderr
                else:
                    self.log.info('%s enabled.' % module)

        if self.version == 6:
            drupal_vars = {
                'apachesolr_search_make_default': 1,
                'apachesolr_search_spellcheck': 1,
                'cache': '3',
                'block_cache': '1',
                'page_cache_max_age': '900',
                'page_compression': '0',
                'preprocess_js': '1',
                'preprocess_css': '1'
            }

        elif self.version == 7:
            drupal_vars = {
                'cache': 1,
                'block_cache': 1,
                'cache_lifetime': "0",
                'page_cache_maximum_age': "900",
                'page_compression': 0,
                'preprocess_css': 1,
                'preprocess_js': 1,
                'search_active_modules': {
                    'apachesolr_search': 'apachesolr_search',
                    'user': '******',
                    'node': 0
                },
                'search_default_module': 'apachesolr_search'
            }

        # Set variables.
        (db_username, db_password,
         db_name) = pantheon.get_database_vars(self, 'dev')
        db = dbtools.MySQLConn(database=db_name,
                               username=db_username,
                               password=db_password)
        for key, value in drupal_vars.iteritems():
            db.vset(key, value)

        # apachesolr module for drupal 7 stores config in db.
        # TODO: use drush/drupal api to do this work.
        try:
            if self.version == 7:
                db.execute('TRUNCATE apachesolr_environment')
                for env in self.environments:
                    config = self.config['environments'][env]['solr']

                    env_id = '%s_%s' % (self.project, env)
                    name = '%s %s' % (self.project, env)
                    url = 'http://%s:%s%s' % (config['solr_host'],
                                              config['solr_port'],
                                              config['solr_path'])

                    # Populate the solr environments
                    db.execute('INSERT INTO apachesolr_environment ' + \
                        '(env_id, name, url) VALUES ' + \
                        '("%s", "%s", "%s")' % (env_id, name, url))

                    # Populate the solr environment variables
                    db.execute('INSERT INTO apachesolr_environment_variable '+\
                               '(env_id, name, value) VALUES ' + \
                               "('%s','apachesolr_read_only','s:1:\"0\"')" % (
                                                                      env_id))
        except Exception as mysql_error:
            self.log.error(
                'Auto-configuration of ApacheSolr module failed: %s' %
                mysql_error)
            pass

        db.close()

        # D7: apachesolr config link will not display until cache cleared?
        with settings(warn_only=True):
            result = local('drush @working_dir -y cc all')
            pantheon.log_drush_backend(result, self.log)

        # Run updatedb
        drupaltools.updatedb(alias='@working_dir')

        # Remove temporary working_dir drush alias.
        alias_file = '/opt/drush/aliases/working_dir.alias.drushrc.php'
        if os.path.exists(alias_file):
            local('rm -f %s' % alias_file)