Jump to content

Any alternative ways to put prestashop into maintenace mode ?


MaXi32

Recommended Posts

Hello there, what are the alternative ways to put prestashop into a maintenance  from the backend server ? 

At this moment, if I want to manually put a prestashop website into maintenance mode, I can manually change the ps_configuration table.

So, I created a bash script and change the database table to maintenance mode like this. This is working for me:
 

        echo "[$script_name | info]: Turning on server maintenance mode for user admin:" | tee -a $REPORT_FILE
        # For lozira.com (prestashop)
        LOZDBUSER="dbuser"
        LOZDBPASS="dbpass"
        LOZDBNAME="dbname"
        # Clear Prestashop IPs from back office
        mysql -u $LOZDBUSER -p$LOZDBPASS -D $LOZDBNAME -e "UPDATE ps_configuration SET value = NULL WHERE ps_configuration.id_configuration = 1002;"
        # Disable prestashop shop from back office
        mysql -u $LOZDBUSER -p$LOZDBPASS -D $LOZDBNAME -e "UPDATE ps_configuration SET value = 1 WHERE ps_configuration.id_configuration = 28;"
        return_code=$?
        if [ $? -eq 0 ]; then
                echo "[$script_name | info]: OK, the website of domain.com is now under maintenance mode" | tee -a $REPORT_FILE
        else
                echo "[$script_name | info]: Warning, unable to put website of domain.com in maintenance mode" | tee -a $REPORT_FILE
        fi

The front page is under maintenace mode but I notice I can still access into the back office domain.com/backofficeurl (this is what I don't want). I also want to block admin users from accessing the back office until the script finished running.

Another way I can think of is creating maintenance using .htaccess in the root domain and then another htaccess inside domain.com/backofficeurl.. but is that one of the alternative approaches ? How do you put the entire site including people at the back office who won't be able to log into dashboard ? Then you can enable this from the server. I know how to do this in wordpress using .maintenance file but in prestashop I don't find any alternative ways. Is there an approach like wordpress .maintenace file ?

Edited by arafatx (see edit history)
Link to comment
Share on other sites

5 minutes ago, musicmaster said:

You might consider to put all the employees in the employee table as "inactive".

Ok that is a great idea. But, I forgot to mention, I don't want to write script using sql like above because it has sensitive information about db login. I mean is there alternative way other than changing the database table ? If no way I think setting the employee table as inactive is the best idea.

Edited by arafatx (see edit history)
Link to comment
Share on other sites

I'm writing the script to put all website in maintenance mode. The bash script is dynamic so it will identify which user to put into maintenace mode, using sql statement is not good here to identify which web_user. So if there is a way like using file based maintenance mode (like wordpress) I really like to know this:     

  #web_user="userwordpress"

        #web_domain="mywsite.com"
        #web_sub_folder="www"
        #web_type="wordpress"
        #maintenance_status=1 #1 = on, #0 = off

       web_user="userprestashop"

       web_domain="mypssite.com"
        web_sub_folder="www"
        web_type="prestashop"
        maintenance_status=1 #1 = on, #0 = off



        if [ $maintenance_status == 1 ]; then
                if [ "$web_type" == "wordpress" ]; then
                        echo "[$script_name | info]: Turning on server maintenance mode for user $web_user" | tee -a $REPORT_FILE
                        maintenance_file="/home/$web_user/domains/$web_domain/public_html/$web_sub_folder/.maintenance"
                        if [ -f $maintenance_file ]; then
                                echo "[$script_name | info]: OK, the website of $web_domain is already in a maintenance mode" | tee -a $REPORT_FILE
                        else
                                touch $maintenance_file
                                echo "# AUTO GENERATED BY MAXIRSYNC BACKUP CRON" >> $maintenance_file
                                echo "<?php" >> $maintenance_file
                                echo "$upgrading = time();" >> $maintenance_file
                                echo "?>" >> $maintenance_file
                                chmod 644 $maintenance_file
                                chown $web_user:$web_user
                                echo "[$script_name | info]: OK, the website of $web_domain is now under maintenance mode" | tee -a $REPORT_FILE
                        fi
                fi
                if [ "$web_type" == "prestashop" ]; then
                        # Prestashop put maintenance mode
                fi
        else # maintenance status = 0
                if [ "$web_type" == "wordpress" ]; then
                        if [ -f $maintenance_file ]; then
                                rm -f $maintenance_file
                        fi
                else
                        # Prestashop put back live mode
                fi
        fi

 

Edited by arafatx (see edit history)
Link to comment
Share on other sites

Ok I think the best is using htaccess for all website. So, I don't have to query SQL: This code is working fine here:

 

        web_user="admin"
        web_domain="mypswebsite.com" # 
        web_sub_folder=""
        web_type="prestashop"
        admin_path="admin"
        maintenance_status=1 #1 = on, #0 = off

        # DEFINE FIXED PATH for all maintenance htaccess sites
        maintenance_htaccess_www="/home/$web_user/domains/$web_domain/public_html/$web_subfolder/.htaccess"
        # DEFINE ANOTHER PATH for htaccess maintenance file
        # for prestashop maintenance file
        ps_maintenance_htaccess_admin="/home/$web_user/domains/$web_domain/public_html/$web_subfolder/$admin_path/.htaccess"

        if [ $maintenance_status == 1 ]; then
                echo "[$script_name | info]: Turning on server maintenance mode for user $web_user" | tee -a $REPORT_FILE
                # rename current htaccess as backup .htaccess_x
                mv -f "${maintenance_htaccess_www}" "${maintenance_htaccess_www}_x"
                # create .htaccess file with maintenance content including the html (overwrite)
                touch $maintenance_file_www
                echo "# AUTO GENERATED BY MAXIRSYNC BACKUP CRON" >> $maintenance_htaccess_www
                echo "# This htaccess putting website $web_domain into maintenance mode" >> $maintenance_htaccess_www
                echo "RewriteEngine on" >> $maintenance_htaccess_www
                echo "RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]" >> $maintenance_htaccess_www
                echo "RewriteRule .* /maintenance.html [R=302,L]" >> $maintenance_htaccess_www
                # wait 1 seconnd
                chmod 644 $maintenance_htaccess_www
                chown $web_user:$web_user
                sleep 1
                if [ "$web_type" == "prestashop" ]; then
                        # DO PRESTASHOP THING
                        # rename current htccess inside admin_dash into .htaccess_y
                        mv -f "${ps_maintenance_htaccess_admin}" "${ps_maintenance_htaccess_admin}_y"
                        # copy the same .htaccess including permission file from root to admin_dash
                        cp -p "${maintenance_file_www}" "${ps_maintenance_htaccess_admin}"
                elif [ "$web_type" == "wordpress" ]; then
                        # DO EXTRA WORDPRESS THING
                        :
                fi
                echo "[$script_name | info]: OK, the website of $web_domain is now under maintenance mode" | tee -a $REPORT_FILE
        else # maintenance status = 0
                # rename the backup .htaccess_x into .htaccess (and overwrite)
                mv -f "${maintenance_htaccess_www}_x" "${maintenance_htaccess_www}"
                if [ "$web_type" == "prestashop" ]; then
                        # PS
                        # rename back the admin_path .htaccess_y into .htaccess inside that admin_dash folder (and overwrite)
                        mv -f "${ps_maintenance_htaccess_admin}_y" "${ps_maintenance_htaccess_admin}"
                elif [ "$web_type" == "wordpress" ]; then
                        # WP
                        :
                fi
                echo "[$script_name | info]: OK, the website of $web_domain is now under live mode" | tee -a $REPORT_FILE
        fi

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...