Without a doubt CSV 2 POST is the most complex plugin of its kind. One area that has taking endless hours to perfect is automatic post updating. During the last 2-3 months (Oct-Dec 2012) we found ourselves creating a smart system for post updating that updates posts in response to three different changes. We refer to these as Update Reasons rather than triggers simply because the term ‘trigger’ is being used elsewhere. It’s no big deal really.
What is important to understand is that posts are updated when one of three reasons exist and I will explain each reason below. I should also mention before I continue that this applies to the paid edition only.
1. Changed/Updated Record
Straight away this causes many users confusion because CSV 2 POST imports data to a temporary database table, created by CSV 2 POST automatically, prior to the creation of posts or anything else. This is unique to CSV 2 POST. Our approach is required for advanced features no other plugin provide and we strongly feel this approach is far more fitting for a professional or business.
So to be clear. CSV file rows, are imported and become database records. From there we can do lots of cool things. One thing we can do is update those records, getting data from CSV file into our database, but not actually changing posts. ‘Why do that?’ you may ask. Well it is for many reasons, a long list of reasons but overall it allows us to ‘play around’ with the data before it is make public. I’ll let your imagination come up with some ideas, there are no limits to the data manipulation we can do.
If we update existing records by importing a newer CSV file than the original, this will trigger post updating providing your project is configured for updating and the schedule is setup also. Our auto-blogging plugin is designed for every user and many users do not want every post updated instantly. So by default things happen slowly, in a manner often referred to as drip-feeding or maybe we can call this drip-updating!
The schedule script will query any database records that have changed since they were used to created or update a post. There is a column holding the date and time values of when data was last applied. Comparing that date and time to the one for when the record was changed allows our script to determine what records can be used. It’s actually very simple and the original approach. However it is not enough, not for the best CSV import plugin on WordPress!
Read on to learn and understand the other two post updating reasons that are just as important as the above.
2. Meta Key: csv2post_outdated
All post from now on (since version 6.7.2) will have a new meta value named ‘csv2post_outdated’. The value for this meta will be yes or no. Yes meaning the post is out-of-date and no, well you get the point.
The creation of this new meta was a sudden thought of my own and is a little hint to a larger plan we have for an API. By having this meta value in place any script, if it be in a theme or another plugin, can trigger a post to be updated. Considering another plugin changing the data originally imported using CSV 2 POST. A shopping cart plugin can share the same data with CSV 2 POST, both plugins can be used to manage the data. However the shopping cart plugin would need to update the records changed data and time.
Pretty much along the lines of the first method explained above however by changing the csv2post_outdated value we can flag posts directly. An interface will be created which lists all out-of-date posts. There is no other practical way of being able to flag posts. The flexibility in this is endless i.e. users who do want automatic post updating in place but want to know that posts are out of date then manually update them or even just delete them. How the csv2post_outdated status is interpreted could also be changed to suit a developer i.e. they could use it to indicate that a post is overdue for an update with certain criteria in use to determine that it could or should have been updated.
3. Project Configuration Changed
Whenever the user changes settings in a project a date and time is stored. That date and time is compared to the update date and time stored in a meta value for csv2post_updated. To make this work we also have a value that acts like a switch. The switch is only switched off when CSV 2 POST cannot find any posts that have not been updated since the projects configuration was changed. When the switch is on, CSV 2 POST can quickly determine if any projects have posts requiring updating.
That is the technical workings of it. In short changing a projects configuration is a reason for posts to start being updated but only if the plugins settings allow it. As with everything there are settings to stop or start these features.
I should also mention there are some things in project configuration that do not cause the update i.e. categories, permalink. That can be changed on request. We simply want to avoid users making changes to parts of posts that are normally kept as they.
The Scripts Order
The above post update reasons are typed in order that they happen within our script. This is important to know because all of our automated functions have limits in place, they need to end somewhere right! It means the first update reason could keep the plugin busy and it never really arrives at the other two update reasons within the script, meaning the checks are not done for those. Limits would need to be raised and possibly some customizing if anyone wanted CSV 2 POST to do a lot more processing than we have designed it to do. we have designed it for the average server with 30 second limit on processing.