Web Development Articles

Set A Specific Node ID in Drupal

I have a project that I have been working on for a little while now. Like most projects we work on, we have a staging server to work on the code and the client’s can see what work is being done for approval. This server is different than the production server, for obvious reasons.

I ran into an issue awhile ago where I worked on a Webform node for quite awhile (it was complex). So when I went to roll it out, I created the node on the live site, and it had a different node ID than my local. This is to be expected, as the sites don’t share a database, and the production server is constantly getting new updates.

To fix it, I had to rename my custom template to the live node ID, which makes merging the changes I make later harder. I thought there MUST be a better way.

My first thought was to create the node and then change the local ID to match. But several Stack Overflow messages said avoid that like the plague.

But one SO post had a good idea: change the AUTO INCREMENT value in my local DB!

So what I did was first I created the node on the live site and left it unpublished for now. This new node had the ID of 4994. I then logged into PHPMyAdmin, selected the database for this Drupal site, and ran the following:

ALTER TABLE  `node` AUTO_INCREMENT =4994;

I then went to my staging site and created a new webform and voila! It has the same node ID! So now I won’t have crazy conflicts to deal with.

Better idea? Let me know!

Posted in Drupal

Migrate A CentOS 6 Virtual Server To Another PC Using Virtualbox

There have been a few times where I have needed to migrate a VirtualBox virtual server I have built on one machine to use on another. Usually this is seamless. I simply turn off the server in question, export the appliance to a USB drive or shared folder, import the appliance, and I am all set. This works the same for CentOS 6, except every time that I have done this, the network would refuse to work. I am happy to say I finally found a solution!

After you import the appliance, go into the device settings under network (I always used a bridged adapter), and make sure the device name matches your desired setup. Click Advanced, and refresh the MAC address. Then boot up.

Once booted up, su to root and do the following:

sudo rm -f /etc/udev/rules.d/70-persistent-net.rules

Once rebooted, set your network settings, as needed, to match your network and restart the network service. In my previous attempts, this has fixed the issue.

HTH!

Posted in Linux Tagged with: , ,

Restore Data In MySQL DB from Another MySQL DB

Today a client of mine had an issue where some scripts ran amuck and some data (mainly some timestamp rows) was set to 0. So I had to restore from a backup to fix the issues. The problem is that I couldn’t restore the entire database because today’s data would get lost. It was also only a few columns in a few tables that needed restoring. So here’s what I did.

First, I grabbed a copy of extract_sql.pl, a handy script to have when you want to extract out certain tables from a large MySQL dump file (in this case a 7.7 GB dump file). I used it like this (replace table_name with your table you want to extract):

./extract_sql.pl -t table_name -r daily_backup_2017-03-30_03h00m_Thursday.sql > table_name.sql

I then created a database named `restore` on the same server, and imported the data from the `table_name.sql` file to create and populate the table (my backups include DROP and CREATE statements). Now my `table_name` was in my `restore` database with all of the data up to the last backup.

I then backed up the current table, just in case!

mysqldump -u myuser -p real_database table_name> table_name_backup.sql

Finally, I needed to update just the rows that I wanted, based on conditions in the current database. After searching, I found and modified a solution that worked:

UPDATE
    real_database.table_name live
INNER JOIN
    restore.table_name old ON live.pk = old.pk
SET
    live.add_date = old.add_date,
    live.update_date = old.update_date,
    live.completed_date = old.completed_date
WHERE
    live.add_date = 0

Once I ran the above, all of the data in the restore database updated the data in the live datatbase up to where the backup was made. From there I had to adjust today’s dates, but that was strait forward. I then repeated these steps for each table that needed fixing.

HTH!

Posted in MySQL

Firefox Reports Source File Could Not Be Read

We work on a rather large project that interacts with files stored in the Rackspace Cloud. Users often need to click links to view files saved within orders, and normally this works fine.

Read more ›
Posted in PHP Tagged with: , ,

Hide WordPress Admin Links In Code

Recently on a project the client asked to be able to post testimonials on their site. Normally we install the Testimonials Widget, as it gives us a lot of flexibility, has short codes so we can add to different pages and categorize them, and more. So, in this case, we did, as well, and added a few for them for their approval.

Read more ›
Posted in PHP, Wordpress Tagged with: ,

Redirect All Front-End Pages To Landing Page In WordPress

Today a client of ours announced that they were purchased by another company. Inevitably with this comes website changes, and one change that was needed was to basically phase out the existing corporate website for the purchased company.

Read more ›
Posted in Wordpress Tagged with: ,