Tim Allen on 14 Jul 2017 11:47:11 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] The most pernicious bug in WordPress


This is one of the many reasons I've gotten as far away from WordPress as possible. I'm loving working with Wagtail on Django these days. Good luck setting up a development environment. Or trying to figure out why the taxonomy database design, done for version 3.0, is still completely illogical and backwards.

Things like these led me to write code like this:

@task
def user_db_refresh():
    """
    Makes a copy of the production database, replaces the necessary URLs for the user,
    and overwrites the user database.
    """

    mysql_user = input("MySQL username [sepia]: ") or "sepia"
    mysql_password = getpass("MySQL password: ")
    username = input("Your username [{0}]: ".format(getuser())) or getuser()

    print('Backing up production database...')
    call('mysqldump --max_allowed_packet=16384 --net-buffer-length=1M --user={0} --password={1} mysite > {2}_db.sql'.format(mysql_user, mysql_password, username), shell=True);
    print('Replacing www.mysite with {0}.mysite...'.format(username))
    call('sed -i "s|/var/www/vhosts/user/sites/www.mysite.org/www|/var/www/{0}_mysite/wordpress|g" {0}_db.sql'.format(username), shell=True)
    call('sed -i "s|www.mysite|{0}.mysite|g" {0}_db.sql'.format(username), shell=True)
    call('sed -i "s|http://mysite|http://{0}.mysite|g" {0}_db.sql'.format(username), shell=True)
    # call('sed -i "s/),(/),\n(/g" {0}_db.sql'.format(username), shell=True)
    print('Restoring database to {0}_mysite...'.format(username))
    call('mysql --max_allowed_packet=2147483648 --user={0} --password={1} {2}_mysite < {2}_db.sql'.format(mysql_user, mysql_password, username), shell=True);
    print('Removing temp files...')
    # call('rm -f {0}_db.sql'.format(username), shell=True)
    print('Done.')

...which should NEVER. BE. DONE.

</rant>

Tim

On Thu, Jul 13, 2017 at 7:20 PM, Doug Stewart <zamoose@gmail.com> wrote:


On Thu, Jul 13, 2017 at 7:01 PM, CJ Fearnley <cjf@linuxforce.net> wrote:
On Thu, Jul 13, 2017 at 06:33:49PM -0400, brent timothy saner wrote:
> On 07/13/2017 06:13 PM, Stephen R Guglielmo wrote:
> > I use wp-cli's search-replace command to do this. I often clone our prod
> > wordpress db to non-prod and wp-cli is how I correct the DB.
> >
> > You can't run a regular search/replace on the DB because data is stored
> > serialized (another "why?!?!?"); wp-cli's handles this correctly.
> >
>
> i just do a mysqldump, sed the dump, and import the edited dump for
> wordpress. works fine for me.

I tried that once. It blew up.

Actually I used vim's search and replace. Maybe sed would work better?



That's because of the serialized values in the wp_options tables. You've got to have a search & replace that knows how to deserialize and re-serialize.

Either that, or make your stage and prod domain names the exact same number of characters so you don't have to worry about updating the serialized fields' character counts. It's a stupid trick, but it works.

Also, WP-CLI is a simple phar, so you should be able to keep a copy in your home directory, regardless of your packaging system or distro.

--
-Doug



___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug


___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug