#NEWLINE# def setupwordpress( self , data ) : #NEWLINE# #INDENT# ee_domain_name = e [ 'site_name' ] #NEWLINE# ee_site_webroot = data [ 'webroot' ] #NEWLINE# prompt_wpprefix = self . app . config . get ( 'wordpress' , 'prefix' ) #NEWLINE# ee_wp_user = self . app . config . get ( 'wordpress' , 'user' ) #NEWLINE# ee_wp_pass = self . app . config . get ( 'wordpress' , 'password' ) #NEWLINE# ee_wp_email = self . app . config . get ( 'wordpress' , 'email' ) #NEWLINE# ee_random = '' . join ( random . sample ( ( ( string . ascii_uppercase + string . ascii_lowercase ) + string . digits ) , 15 ) ) #NEWLINE# ee_wp_prefix = '' #NEWLINE# if ( ( 'wp-user' in data . keys ( ) ) and data [ 'wp-user' ] ) : #NEWLINE# #INDENT# ee_wp_user = data [ 'wp-user' ] #NEWLINE# #UNINDENT# if ( ( 'wp-email' in data . keys ( ) ) and data [ 'wp-email' ] ) : #NEWLINE# #INDENT# ee_wp_email = data [ 'wp-email' ] #NEWLINE# #UNINDENT# if ( ( 'wp-pass' in data . keys ( ) ) and data [ 'wp-pass' ] ) : #NEWLINE# #INDENT# ee_wp_pass = data [ 'wp-pass' ] #NEWLINE# #UNINDENT# Log . info ( self , 'Downloading WordPress \t\t' , end = '' ) #NEWLINE# EEFileUtils . chdir ( self , '{0}/htdocs/' . format ( ee_site_webroot ) ) #NEWLINE# try : #NEWLINE# #INDENT# if EEShellExec . cmd_exec ( self , 'wp --allow-root core download' ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# Log . info ( self , ( ( ( ( ( '[' + Log . ENDC ) + Log . FAIL ) + 'Fail' ) + Log . OKBLUE ) + ']' ) ) #NEWLINE# raise SiteError ( 'download WordPress core failed' ) #NEWLINE# #UNINDENT# #UNINDENT# except CommandExecutionError as e : #NEWLINE# #INDENT# Log . info ( self , ( ( ( ( ( '[' + Log . ENDC ) + Log . FAIL ) + 'Fail' ) + Log . OKBLUE ) + ']' ) ) #NEWLINE# raise SiteError ( self , 'download WordPress core failed' ) #NEWLINE# #UNINDENT# Log . info ( self , ( ( ( ( '[' + Log . ENDC ) + 'Done' ) + Log . OKBLUE ) + ']' ) ) #NEWLINE# if ( not ( data [ 'ee_db_name' ] and data [ 'ee_db_user' ] and data [ 'ee_db_pass' ] ) ) : #NEWLINE# #INDENT# data = setupdatabase ( self , data ) #NEWLINE# #UNINDENT# if ( ( prompt_wpprefix == 'True' ) or ( prompt_wpprefix == 'true' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ee_wp_prefix = input ( 'Enter the WordPress table prefix [wp_]: ' ) #NEWLINE# while ( not re . match ( '^[A-Za-z0-9_]*$' , ee_wp_prefix ) ) : #NEWLINE# #INDENT# Log . warn ( self , 'table prefix can only contain numbers, letters, and underscores' ) #NEWLINE# ee_wp_prefix = input ( 'Enter the WordPress table prefix [wp_]: ' ) #NEWLINE# #UNINDENT# #UNINDENT# except EOFError as e : #NEWLINE# #INDENT# Log . debug ( self , '{0}' . format ( e ) ) #NEWLINE# raise SiteError ( 'input table prefix failed' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not ee_wp_prefix ) : #NEWLINE# #INDENT# ee_wp_prefix = 'wp_' #NEWLINE# #UNINDENT# EEFileUtils . chdir ( self , '{0}/htdocs/' . format ( ee_site_webroot ) ) #NEWLINE# Log . debug ( self , 'Setting up wp-config file' ) #NEWLINE# if ( not data [ 'multisite' ] ) : #NEWLINE# #INDENT# Log . debug ( self , 'Generating wp-config for WordPress Single site' ) #NEWLINE# Log . debug ( self , ( ( ( 'bash -c "php {0} --allow-root ' . format ( EEVariables . ee_wpcli_path ) + 'core config ' ) + "--dbname='{0}' --dbprefix='{1}' --dbuser='{2}' --dbhost='{3}' " . format ( data [ 'ee_db_name' ] , ee_wp_prefix , data [ 'ee_db_user' ] , data [ 'ee_db_host' ] ) ) + '--dbpass= --extra-php<<PHP \n {1}\nPHP"' . format ( data [ 'ee_db_pass' ] , "\n\ndefine('WP_DEBUG', false);" ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# if EEShellExec . cmd_exec ( self , ( ( ( 'bash -c "php {0} --allow-root' . format ( EEVariables . ee_wpcli_path ) + ' core config ' ) + "--dbname='{0}' --dbprefix='{1}' --dbuser='{2}' --dbhost='{3}' " . format ( data [ 'ee_db_name' ] , ee_wp_prefix , data [ 'ee_db_user' ] , data [ 'ee_db_host' ] ) ) + '--dbpass=\'{0}\' --extra-php<<PHP \n {1} {redissalt}\nPHP"' . format ( data [ 'ee_db_pass' ] , "\n\ndefine('WP_DEBUG', false);" , redissalt = ( "\n\ndefine( 'WP_CACHE_KEY_SALT', '{0}:' );" . format ( ee_domain_name ) if data [ 'wpredis' ] else '' ) ) ) , log = False ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise SiteError ( 'generate wp-config failed for wp single site' ) #NEWLINE# #UNINDENT# #UNINDENT# except CommandExecutionError as e : #NEWLINE# #INDENT# raise SiteError ( 'generate wp-config failed for wp single site' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# Log . debug ( self , 'Generating wp-config for WordPress multisite' ) #NEWLINE# Log . debug ( self , ( ( ( 'bash -c "php {0} --allow-root ' . format ( EEVariables . ee_wpcli_path ) + 'core config ' ) + "--dbname='{0}' --dbprefix='{1}' --dbhost='{2}' " . format ( data [ 'ee_db_name' ] , ee_wp_prefix , data [ 'ee_db_host' ] ) ) + '--dbuser=\'{0}\' --dbpass= --extra-php<<PHP \n {2} {3} {4}\nPHP"' . format ( data [ 'ee_db_user' ] , data [ 'ee_db_pass' ] , "\ndefine('WP_ALLOW_MULTISITE', true);" , "\ndefine('WPMU_ACCEL_REDIRECT', true);" , "\n\ndefine('WP_DEBUG', false);" ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# if EEShellExec . cmd_exec ( self , ( ( ( 'bash -c "php {0} --allow-root' . format ( EEVariables . ee_wpcli_path ) + ' core config ' ) + "--dbname='{0}' --dbprefix='{1}' --dbhost='{2}' " . format ( data [ 'ee_db_name' ] , ee_wp_prefix , data [ 'ee_db_host' ] ) ) + '--dbuser=\'{0}\' --dbpass=\'{1}\' --extra-php<<PHP \n {2} {3} {4} {redissalt}\nPHP"' . format ( data [ 'ee_db_user' ] , data [ 'ee_db_pass' ] , "\ndefine('WP_ALLOW_MULTISITE', true);" , "\ndefine('WPMU_ACCEL_REDIRECT', true);" , "\n\ndefine('WP_DEBUG', false);" , redissalt = ( "\n\ndefine( 'WP_CACHE_KEY_SALT', '{0}:' );" . format ( ee_domain_name ) if data [ 'wpredis' ] else '' ) ) ) , log = False ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise SiteError ( 'generate wp-config failed for wp multi site' ) #NEWLINE# #UNINDENT# #UNINDENT# except CommandExecutionError as e : #NEWLINE# #INDENT# raise SiteError ( 'generate wp-config failed for wp multi site' ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# import shutil #NEWLINE# Log . debug ( self , 'Moving file from {0} to {1}' . format ( ( os . getcwd ( ) + '/wp-config.php' ) , os . path . abspath ( os . path . join ( os . getcwd ( ) , os . pardir ) ) ) ) #NEWLINE# shutil . move ( ( os . getcwd ( ) + '/wp-config.php' ) , os . path . abspath ( os . path . join ( os . getcwd ( ) , os . pardir ) ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# Log . error ( self , 'Unable to move file from {0} to {1}' . format ( ( os . getcwd ( ) + '/wp-config.php' ) , os . path . abspath ( os . path . join ( os . getcwd ( ) , os . pardir ) ) ) , False ) #NEWLINE# raise SiteError ( 'Unable to move wp-config.php' ) #NEWLINE# #UNINDENT# if ( not ee_wp_user ) : #NEWLINE# #INDENT# ee_wp_user = EEVariables . ee_user #NEWLINE# while ( not ee_wp_user ) : #NEWLINE# #INDENT# Log . warn ( self , 'Username can have only alphanumericcharacters, spaces, underscores, hyphens,periods and the @ symbol.' ) #NEWLINE# try : #NEWLINE# #INDENT# ee_wp_user = input ( 'Enter WordPress username: ' ) #NEWLINE# #UNINDENT# except EOFError as e : #NEWLINE# #INDENT# Log . debug ( self , '{0}' . format ( e ) ) #NEWLINE# raise SiteError ( 'input WordPress username failed' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not ee_wp_pass ) : #NEWLINE# #INDENT# ee_wp_pass = ee_random #NEWLINE# #UNINDENT# if ( not ee_wp_email ) : #NEWLINE# #INDENT# ee_wp_email = EEVariables . ee_email #NEWLINE# while ( not ee_wp_email ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ee_wp_email = input ( 'Enter WordPress email: ' ) #NEWLINE# #UNINDENT# except EOFError as e : #NEWLINE# #INDENT# Log . debug ( self , '{0}' . format ( e ) ) #NEWLINE# raise SiteError ( 'input WordPress username failed' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# while ( not re . match ( '^[A-Za-z0-9\\.\\+_-]+@[A-Za-z0-9\\._-]+\\.[a-zA-Z]*$' , ee_wp_email ) ) : #NEWLINE# #INDENT# Log . info ( self , 'EMail not Valid in config, Please provide valid email id' ) #NEWLINE# ee_wp_email = input ( 'Enter your email: ' ) #NEWLINE# #UNINDENT# #UNINDENT# except EOFError as e : #NEWLINE# #INDENT# Log . debug ( self , '{0}' . format ( e ) ) #NEWLINE# raise SiteError ( 'input WordPress user email failed' ) #NEWLINE# #UNINDENT# Log . debug ( self , 'Setting up WordPress tables' ) #NEWLINE# if ( not data [ 'multisite' ] ) : #NEWLINE# #INDENT# Log . debug ( self , 'Creating tables for WordPress Single site' ) #NEWLINE# Log . debug ( self , ( ( 'php {0} --allow-root core install ' . format ( EEVariables . ee_wpcli_path ) + "--url='{0}' --title='{0}' --admin_name='{1}' " . format ( data [ 'www_domain' ] , ee_wp_user ) ) + "--admin_password= --admin_email='{1}'" . format ( ee_wp_pass , ee_wp_email ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# if EEShellExec . cmd_exec ( self , ( ( 'php {0} --allow-root core ' . format ( EEVariables . ee_wpcli_path ) + "install --url='{0}' --title='{0}' --admin_name='{1}' " . format ( data [ 'www_domain' ] , ee_wp_user ) ) + "--admin_password='{0}' --admin_email='{1}'" . format ( ee_wp_pass , ee_wp_email ) ) , log = False ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise SiteError ( 'setup WordPress tables failed for single site' ) #NEWLINE# #UNINDENT# #UNINDENT# except CommandExecutionError as e : #NEWLINE# #INDENT# raise SiteError ( 'setup WordPress tables failed for single site' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# Log . debug ( self , 'Creating tables for WordPress multisite' ) #NEWLINE# Log . debug ( self , ( ( 'php {0} --allow-root ' . format ( EEVariables . ee_wpcli_path ) + "core multisite-install --url='{0}' --title='{0}' --admin_name='{1}' " . format ( data [ 'www_domain' ] , ee_wp_user ) ) + "--admin_password= --admin_email='{1}' {subdomains}" . format ( ee_wp_pass , ee_wp_email , subdomains = ( '--subdomains' if ( not data [ 'wpsubdir' ] ) else '' ) ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# if EEShellExec . cmd_exec ( self , ( ( 'php {0} --allow-root ' . format ( EEVariables . ee_wpcli_path ) + "core multisite-install --url='{0}' --title='{0}' --admin_name='{1}' " . format ( data [ 'www_domain' ] , ee_wp_user ) ) + "--admin_password='{0}' --admin_email='{1}' {subdomains}" . format ( ee_wp_pass , ee_wp_email , subdomains = ( '--subdomains' if ( not data [ 'wpsubdir' ] ) else '' ) ) ) , log = False ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise SiteError ( 'setup WordPress tables failed for wp multi site' ) #NEWLINE# #UNINDENT# #UNINDENT# except CommandExecutionError as e : #NEWLINE# #INDENT# raise SiteError ( 'setup WordPress tables failed for wp multi site' ) #NEWLINE# #UNINDENT# #UNINDENT# Log . debug ( self , 'Updating WordPress permalink' ) #NEWLINE# try : #NEWLINE# #INDENT# EEShellExec . cmd_exec ( self , ( ' php {0} --allow-root ' . format ( EEVariables . ee_wpcli_path ) + 'rewrite structure /%year%/%monthnum%/%day%/%postname%/' ) ) #NEWLINE# #UNINDENT# except CommandExecutionError as e : #NEWLINE# #INDENT# raise SiteError ( 'Update wordpress permalinks failed' ) #NEWLINE# #UNINDENT# 'Install nginx-helper plugin ' #NEWLINE# installwp_plugin ( self , 'nginx-helper' , data ) #NEWLINE# if data [ 'wpfc' ] : #NEWLINE# #INDENT# plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_fastcgi","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}' #NEWLINE# setupwp_plugin ( self , 'nginx-helper' , 'rt_wp_nginx_helper_options' , plugin_data , data ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if data [ 'wpredis' ] : #NEWLINE# #INDENT# plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}' #NEWLINE# setupwp_plugin ( self , 'nginx-helper' , 'rt_wp_nginx_helper_options' , plugin_data , data ) #NEWLINE# #UNINDENT# #UNINDENT# 'Install Wp Super Cache' #NEWLINE# if data [ 'wpsc' ] : #NEWLINE# #INDENT# installwp_plugin ( self , 'wp-super-cache' , data ) #NEWLINE# #UNINDENT# 'Install Redis Cache' #NEWLINE# if data [ 'wpredis' ] : #NEWLINE# #INDENT# installwp_plugin ( self , 'redis-cache' , data ) #NEWLINE# #UNINDENT# 'Install W3 Total Cache' #NEWLINE# if ( data [ 'w3tc' ] or data [ 'wpfc' ] ) : #NEWLINE# #INDENT# installwp_plugin ( self , 'w3-total-cache' , data ) #NEWLINE# #UNINDENT# wp_creds = dict ( wp_user = ee_wp_user , wp_pass = ee_wp_pass , wp_email = ee_wp_email ) #NEWLINE# return wp_creds