This question has been answered by BobRay. See the first response.
i would like to find from a symlink, the original resource. symlinks have [[*content]] id, so i guess this id is the original document XD
thanks for your help.
$originalId = 12; $symlinks = $modx->getCollection('modSymLink', array('content' => $originalId)); $output = "Symlinks for Doc " . $originalId; $output .= "<ul>"; foreach ($symlinks as $doc) { $output .= '<li>ID: ' . $doc->get('id') . '</li>'; } $output .= "</ul>"; return $output;
$symlinks = $modx->getCollection('modResource', array('class_key' => 'modSymLink')); $originals = array(); $output = ''; $targets = array(); foreach ($symlinks as $symlink) { $symlinkId = $symlink->get('id'); $targetId = $symlink->get('content'); $targets[$targetId][$symlinkId] = $symlink->get('pagetitle'); } foreach ($targets as $targetId => $symlinks) { $indent = ' '; $original = $modx->getObject('modResource', $targetId); $originalPagetitle = $original->get('pagetitle'); $ctx = $original->get('context_key'); $originalId = $original->get('id'); $output .= "\n" . '<br><br>Original: <a href="' . MODX_MANAGER_URL . '?a=resource/update&id=' . $originalId . '">' . $originalPagetitle . ' (' . $originalId . ')</a>'; $output .= "\n<br>Symlinks:"; foreach ($symlinks as $id => $pagetitle) { $output .= "\n<br>{$indent}" . '<a href = "' . MODX_MANAGER_URL . '?a=resource/update&id=' . $id . '" > ' . $pagetitle . ' (' . $id . ')</a>'; } } return $output;
Yes, that's correct. There is no table connecting symlinks to original resources.
There is no easy way to go from the original to the symlinks, but you can always find the original in the Resource Content field of the symlink.
If you have many symlinks to one original, I think this utility snippet would find the Symlinks for that original:
$originalId = 12; $symlinks = $modx->getCollection('modSymLink', 'content' => $originalId)); $output = "Symlinks for Doc " . $originalId; $output .= "<ul>"; foreach ($symlinks as $doc) { $output .= '<li>ID: ' . $doc->get('id') . '</li>'; } $output .= "</ul>"; return $output;
This version should find and report all symlinks (untested):
$allDocs = $modx->getCollection('modResource'); $originals = array() foreach ($allDocs as $doc) { $id = $doc->get('id'); if ($doc->get('class_key' == 'modSymLink') { if (isset($originals[$id])) { $originals[$id] .= ',' . $doc->get('content'); } else { $originals[$id] = $doc->get('content'); } } } $output = '<pre>'; foreach ($originals as $original => $symlinks) { $output .= ' Original: ' . $original . ' ' ' . $symlinks; } $output .= '</pre>'; return $output;