New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ProcessWire > 2.6.4: issues with PageLinkAbstractor in multilanguage environment #1283
Comments
PageLinkAbstractor has been deprecated (and no longer in the modules directory) since 2.5, as the functionality is now built into the Textarea field (by choosing one of the Content Type options: Markup or Markup with Images, on the details tab). If possible, unininstall PageLinkAbstractor and use the core built-in functionality. But this might be a pain if you've got a lot of links that were managed by it, as the markup would need to be adjusted. If that's the case, let me know and I can suggest a way to convert them from the API side. |
Interesting to read that PageLinkAbstractor is depreceated. Maybe I overlooked some information there - can't remember having read about this. PageLinkAbstractor is one of the modules I always installed. I like what it does and it shows it's importance that the functionality somehow became now part of the core. I am pretty sure a lot of people used this module. Can I simply de-install PageLinkAbstractor without loosing information? From what you write, not. (And also I would like to receive information right in time in case a module like this is deprecated so suddenly and replaced so I have a chance to wait with a core update or take other precautions.) |
Dear Ryan, I use this module in quite a lot of projects and would be very glad if you could advise how to convert the links from API side. I can't say if too often: big thanks for this great framework and your support efforts. |
I don't have a site to test this on, so am just writing in the browser, and if you try this, make sure to try it on a test scenario before a production one. But the process is to take the abstracted URLs and convert them back to the original URLs, for any fields where you've used it. Then when you save the page, it should update them to use the new abstraction automatically.
|
Btw, I also recommend enabling the PagePathHistory module, which is what handles the situation where linked page URLs change. This is preferable to what PageLinkAbstractor did because it also accounts for the situation of external URLs linking into your site. |
Thanks a lot for the migration code!! Playing with it gave me this:
Cache is off By the way: I put this code around it so that guests cannot see what I am doing: |
Dear Ryan, thanks a lot! I tried out the code as well. The last loop needs a small correction: $page->set($fieldName, $value);
$page->save($fieldName); has to be: $item->set($fieldName, $value);
$item->save($fieldName); With that fix it's working great! I slightly modified the code so I can use it from the command line by bootstrapping ProcessWire. My entire code: <?php
include './index.php';
$pages = wire()->pages;
$config = wire()->config;
$fieldName = 'body';
// replace {~root_url} references
$items = $pages->find("$fieldName%=root_url, include=all");
foreach ($items as $item) {
$item->of(false);
$value = $item->get($fieldName);
if (strpos($value, '{~root_url}') === false) {
continue;
}
$value = str_replace('{~root_url}', $config->urls->root, $value);
$item->set($fieldName, $value);
$item->save($fieldName);
echo "\nUpdated root_url reference on page $item->path";
}
// replace {~page_123_url} references
$items = $pages->find("$fieldName%='page_', include=all");
foreach ($items as $item) {
$item->of(false);
$value = $item->get($fieldName);
if (!preg_match_all('/\{~page_(\d+)_url\}/', $value, $matches)) {
continue;
}
foreach ($matches[1] as $key => $pageID) {
$linkedPage = $pages->get((int)$pageID);
if (!$linkedPage->id) {
echo "\nUnable to find page: $pageID";
continue;
}
$value = str_replace($matches[0][$key], $linkedPage->url(), $value);
$item->set($fieldName, $value);
$item->save($fieldName);
echo "\nUpdated link for page $item->path linking to $linkedPage->path";
}
} |
The fix worked....somehow. - I could restore some of the links easily. |
Test case:
Problem: If an image is added to the first language textarea field, the content of the second language textarea field vanishes after saving. Issue came up with commit 690821d (ProcessWire > 2.6.4); before that, everything was fine.
The text was updated successfully, but these errors were encountered: