• Problem with makeUrl in plugin on OnDocFormSave#

  • bounz Reply #1, 1 year, 9 months ago

    Reply
    Hi everyone!
    I have problem writing plugin for crossposting documents to livejournal.
    For the post in livejournal I need URL of the page from my site. When I create document and save it for the first time, plugin fires, but $modx->makeUrl($id, '', '', 'full') generates URLs like 'http://inaltravel.ru/548.html', but I have my document inside tree and friendly URLs on. When I save my document again the same code generates right url like 'http://inaltravel.ru/countries/specials/548.html'.

    How can I fix it?


  • netProphET - MODX Complete Team Reply #2, 1 year, 9 months ago

    Reply
    It may have something to do with $modx->aliasListing not getting updated during first document save, but I'd have to look deeper.
    The best way to ensure that this gets resolved would be to file a bug report in Jira with this information.
    For a quick fix, you would have to get your plugin "do the math" to create the friendly URL you need if the API isn't working for you.
    One question I have, if on the second or subsequent save, and you change the alias, does your plugin report the correct (new) URL or the previous one?


  • bounz Reply #3, 1 year, 9 months ago

    Reply
    Thank you for your reply, I'll try to do "the math" myself.
    According to your question, I've changed several times the alias of document and it changes in return of makeUrl() only after second save. So for example:
    1. I create new document without alias - wrong URL without full path as I described in first post.
    2. I open and save document again - getting right URL
    3. Open, change alias to smth. - getting wrong URL with previous alias (same, as in 2nd point)
    4. Open and save - getting right URL with new alias
    .. and so on.


  • sottwell Reply #4, 1 year, 9 months ago

    Reply
    Try a different event; it sounds like the event you're using is before the cache gets updated, you need one after the cache gets updated since the makeURL function will use the cache, not the database.

    OnCacheUpdate should do the job; although you'll need some extra code in there to make sure it's being updated because a relevant resource has been created or edited.


  • bounz Reply #5, 1 year, 5 months ago

    Reply
    Thank you guys and sorry for very late reply.
    I had to wrote my own URL-constructor because it is a cache problem - at time the article is created and saved for the very first time and plugin fires on event, there is no way to get it full URL using standart functions.

    Here is my implementation:
    $new_url = $id.".html";
    $parentId = $id;
    while($modx->getParent($parentId,0,'alias, id') != false)
    {
      $parent = $modx->getParent($parentId,0,'alias, id');
      $parentId = $parent['id'];
      $new_url = $parent['alias']."/".$new_url;
    }
    $new_url = MODX_SITE_URL.$new_url;
    $url = $new_url;
    


    Maybe it will help somebody.