Repaired my WordPress Blogs

Over the past few months, my blogs went down for one reason or the other:

  1. Blog – https://dushyant.ahuja.ws went down as there was a virus that had infected the blog – created thousands of random php files.
  2. PhotoBlog – https://photos.ahuja.ws went down as the YAPB plugin finally gave up – it hasn’t been maintained in years and the website started giving a critical error. Probably because I updated the PHP version to 8.

Blog

Somehow, I didn’t have any backups for my Blog – probably lost them in the many times I’ve reorganised my backups and lost my 10TB drive.

Anyways, the only option I had was to download the folder and setup a local instance of wordpress (setup on my server under docker). Was able to use one of the standard wordpress docker images and imported the sql backup into it. Surprise – surprise – the local version of the website came up immediately – though the images did not come in. That was a simple process of copying the jpg files from the ‘uploads’ folder from my backup into the new site, and ensuring that the permissions were setup correctly. The blog is now up and running – though some items like photo galleries and some plugins are not working.

The intent is to move this blog to a static site – either through hugo or pelican. For the time being, it’s working.

PhotoBlog

Making this work was slightly more involved as the moment I enabled the autofocus template that I’ve used for years, the website would go down. Secondly, I needed to convert all the posts from ‘YAPB’ to the wordpress featured image format. Searched the internet to see if there was a way to move from YAPB. Found a link to a plugin that the original writer of YAPB had written to move out of YAPB, however the link no longer works, and there was nothing on archive.org as well.

Next I found a PHP script that someone had written to export YAPB images – but couldn’t run it and it just didn’t work for me.

Moved on to ChatGPT – asked it to convert the PHP script into a wordpress plugin that I could import onto my site and convert all the YAPB images into featured images for the posts. After a couple of iterations, the plugin “worked” but made no changes.

Started to read the script to understand what it was doing and realised that since wordpress works primarily on SQL, I can probably update the mySQL database directly. So it was back to ChatGPT with the following prompt:

I'm using wordpress - I have a table with a list of all the image URLs and post ID where the image is to be inserted. Can you help write an SQL script that would take the image URLs and attach them to the post ID as the featured image

After a couple of iterations fine-tuning the code, I ended up with the following three commands

  1. Insert the image URLs from wp_yapbimage into wp_posts as attachments
INSERT INTO wp_posts (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
SELECT
    1, -- Default author ID, adjust if needed
    NOW(), -- Current timestamp
    NOW(), -- Current timestamp in GMT
    '', -- Empty content
    SUBSTRING_INDEX(wp_yapbimage.URI, '/', -1), -- Use the file name as the title
    '', -- Empty excerpt
    'inherit', -- Attachment post status
    'closed', -- Comment status
    'closed', -- Ping status
    '', -- Empty password
    SUBSTRING_INDEX(wp_yapbimage.URI, '/', -1), -- Use the file name as the slug
    '', -- Empty to_ping
    '', -- Empty pinged
    NOW(), -- Current timestamp for modified date
    NOW(), -- Current timestamp for modified GMT
    '', -- Empty content filtered
    wp_yapbimage.post_id, -- Link the attachment to its parent post
    wp_yapbimage.URI, -- The image URL
    0, -- Default menu order
    'attachment', -- Post type
    'image/jpeg', -- Mime type (adjust if necessary)
    0 -- Default comment count
FROM wp_yapbimage;
  1. Link the attachment as the featured image for posts
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT
    wp_yapbimage.post_id, -- The post ID to assign the featured image
    '_thumbnail_id', -- Meta key for featured image
    wp_posts.ID -- The ID of the attachment
FROM wp_posts
INNER JOIN wp_yapbimage ON wp_posts.guid = wp_yapbimage.URI
WHERE wp_posts.post_type = 'attachment';
  1. Had to insert this after testing and failing to get the thumbnails to display:
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT
    posts.id,
    '_wp_attached_file',
    posts.post_title
FROM wp_posts posts
INNER JOIN wp_postmeta ON wp_postmeta.meta_value = posts.id AND wp_postmeta.meta_key='_thumbnail_id'
  1. Add the image into the post content
UPDATE wp_posts AS posts
INNER JOIN wp_yapbimage AS images ON posts.ID = images.post_id
SET posts.post_content = CONCAT(posts.post_content, '<img src="', images.URI, '" alt="', SUBSTRING_INDEX(images.URI, '/', -1), '">');

This allowed me to update all the posts with a featured image as well as the image in the post body.

  1. Installed the cubico theme. Though had to add the following to style.css to ensure the image stayed within the page and disable the featured image in the post page.
img {
  max-width: 90%;
  height: auto;
  margin: 0 auto;
}

2020 – the year that changed the world

Every year, I spend some time to review and appreciate all the good things that have happened over the year. This is year is no different, and I would like to share my thoughts with you. This year has been difficult for most people, and all of us have gone through hardships due to circumstances beyond our control. The world was brought to its knees by a virus, but humanity grew in response – we helped people, we raised our standards, we fought back. The global economy went into a tailspin, but new ventures came up, we found new avenues for growth, we persevered.

Personally, the year had a lot to offer; some of the important ones being:

1.       Family Time. I was in London when the global lockdowns started; and while the lockdown was not as strict in India, offices were shut down and all of us were working from home. I saved time from my commute, we had all our meals together. Breakfast was a leisurely affair, instead of a sandwich on the train; lunch was eaten in peace with family, instead of on a desk with a computer in front of you. Instead of spending the evenings in packed trains, we spent our time walking, cycling and skating in the parks. We were able to appreciate the small things in life, that we had somehow missed in the hustle and bustle of life. We started a habit of reading books aloud to each other, and spent many enjoyable hours of quality time. I moved back from London, and was able to spend time with my parents – it was after many years, that I was able to stay with them for months, instead of days.  

2.       Healthier Lifestyle. We cooked a lot more at home, ate healthy foods, went for walks (still don’t exercise regularly though, and that’s on the agenda).

3.       Career-wise; I have grown over the year and am extremely lucky to work with professional team members

Globally, the world has gone through a transformation, and people have started realizing that there are different ways – maybe not better, but definitely different:

1.       Digitisation has played a huge role in the New Normal – things that required face to face meetings, and travel; are being done over video calls. Teams, Zoom, etc. have become a boon for most companies. Not only has collaboration and productivity increased, costs have come down as well. Working from home has become a part of life, even in cultures where being in office was always “required”. While some jobs cannot be done online, many people are saving time and money by not travelling. Whether it’s an hour’s daily commute or frequent business meetings around the world, that travel time adds up and can now be spent on more quality pursuits.

2.       Health – new ways to provide basic healthcare were found – telehealth, video conference – again technology led the way here. For the first time in the history of medicine, multiple companies pooled their resources to develop a vaccine. The speed with which the vaccines are being developed is nothing short of miraculous. Mental health challenges have reduced as it has become easier for people to communicate and reach out; a new mindset has developed where people don’t think twice before helping out.

3.       A greener earth – reduced pollution and carbon emissions, cleaner waterways, expanded green areas – all are leading to a greener, healthier world.

4.       Many people lost jobs; but turned this into opportunities that they would have never thought of otherwise. Innovative thinkers, no matter their education, came up with business plans at every level – whether it’s new apps like the ones from right-hear.com/top-apps-for-visually-impaired-people/, or business selling tea and homemade food . People were thrown out of their comfort zones, but rose to the occasion.

5.       Even in our industry, we have had time to think back and reflect, to look at different ways things can be done more efficientlyHygiene and Safety have come to the forefront, smart workplaces are the need for the day. We have had time to upgrade systems that would have been impossible to do earlier.

It wasn’t all fun and games though, there were many difficult days as well – worrying about the future, recovering from COVID, dealing with meltdowns, leaving friends and colleagues behind; but those are things we don’t need to dwell upon. One of my favourite books by author Sir Terry Pratchett mentions an ancient curse – “May you live in Interesting Times”; unfortunately – or fortunately – we are living in interesting times, and how we deal with these times will mould our future. The year ahead would bring more challenges, and consequently more opportunities – we just have to be ready and willing. We need to be right at the forefront of innovative thought; we need to be ready.

It’s very easy to dwell on the negative aspects of life, but seeing the silver lining is more important.

Wish you a happy and blissful 2021

Large 3D Printer

I was reminded by a few colleagues that I have not updated this blog in years now. I guess, I’ve just been too busy playing to blog.

When I had moved to the US (2014), I had backed a kickstarter project called Cobblebot. I’m not even going to link to it here as it was a really bad experience, however it did get me started with 3D printing. With the help of fellow backers on Google+, I was able to build a decent printer that provided me lots of fun. I had never built it for anything serious and most of the things I ended up printing were downloads from thingiverse. But, it was fun nevertheless:

In it’s final version it was able to print a size of 14″x14″x14″; though I never printed anything that large. I built and re-built it multiple times with new upgrades all the time; mainly using ideas from the Google+ community

The first print was a hollow cube:

But went on to print lots of great prints once I had the settings and upgrades done. Some examples include:

[tribulant_slideshow gallery_id=”1″]

One of the best upgrade I did was change the controller from RAMPS that came with the kit to a Cohesion3D ReMIX. It’s 32-bit, runs Smoothieware and makes the motions so smooth and results so amazing, I simply don’t know why everyone still uses the RAMPS controllers. I also wrote a blog post for 3DPrinterChat that describes how you can use the Smoothie compatible boards to easily replace your RAMPS controller. 

Smoothiefy Your Printer

Finally, the printer looked like this, before I disassembled it while moving from the US to UK:

Now, in  London, I’ve started to rebuild it and decided to supersize it:

Don’t ask why I did it; even I don’t know 🙂