Possible to update URL path if publication date of an article in Articles is changed?

Summary

I am using Articles and a number of the individual articles I imported did not have the correct Publication Date specified and so they all were defaulted to the date they were imported and their URL paths reflect this. (Example URL path: mysite.com/news/2020/03/12/article-name/)

Step to reproduce

N/A

Observed behavior

As I am manually correcting their Publication Dates, the URL path is not updating (I have tried clearing the cache and rebuilding URIs but that did nothing). Is there a way to have Articles update URL paths to reflect changes like this?

Expected behavior

I expected that the URL path would change as the Publication Date value was updated.

Environment

MODX 3.1.2 on Linux & Apache 2.4.63 with MySQL 10.5.25-MariaDB-cll-lve

Looking at the code, the URL only seems to get set (or recreated) if the alias or the published state changes:

I guess if you first unpublish the article (and save it). Then set the correct publishedon date and publish it again, the URL should get updated.

I was hopeful that would be do the trick, but unpublishing and republishing simply changed the date to today’s date, so now the URL reflects that instead of the actual publication date of the article. I’m working with an extensive archive of material that needs to have its original publication date. Thanks for the idea, though! I appreciate the quick response.

Did you change the Published On date to the correct one before saving?
Unpublish → Save → Check off “Published” but enter the custom published date → Save again

1 Like

You could also try changing line 53 (in the code I linked above) to this:

if ($this->object->get('published') && ($this->object->isDirty('alias') || $this->object->isDirty('published') || $this->object->isDirty('publishedon'))) {

It should now take changes to the publishedon field into account (even if the published state doesn’t change).


Or if nothing else works, change the value of the uri column in the table modx_site_content directly.

1 Like

It looks like this worked! I’ll try it again on a few others to see if that is the right approach. Thank you!

Just to confirm, this works. It’s a slight variation on the original recommendation, so you’re both right. The exact process is to:

  1. Edit the published article
  2. Unpublish it & save it
  3. Change the Published date
  4. Publish it & save it

This updates the URL path to one that correctly reflects the publication date (in the past).