mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX: Fixed issues with broekn link tracking
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@101138 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
267de8887a
commit
f3a666b89f
@ -1391,9 +1391,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
$this->HasBrokenLink = false;
|
||||
$this->HasBrokenFile = false;
|
||||
|
||||
$formFields = $this->getCMSFields(null);
|
||||
foreach($htmlFields as $field) {
|
||||
$formField = $formFields->dataFieldByName($field);
|
||||
$formField = new HTMLEditorField($field);
|
||||
$formField->setValue($this->$field);
|
||||
$formField->saveInto($this);
|
||||
}
|
||||
@ -2040,7 +2039,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
* @uses SiteTreeDecorator->onAfterUnpublish()
|
||||
*/
|
||||
function doUnpublish() {
|
||||
if(!$this->canDeleteFromLive()) return false;
|
||||
if(!$this->canDeleteFromLive()) return false;
|
||||
if(!$this->ID) return false;
|
||||
|
||||
$this->extend('onBeforeUnpublish');
|
||||
|
@ -71,9 +71,6 @@ class HtmlEditorField extends TextareaField {
|
||||
$linkedPages = array();
|
||||
$linkedFiles = array();
|
||||
|
||||
$record->HasBrokenFile = false;
|
||||
$record->HasBrokenLink = false;
|
||||
|
||||
$htmlValue = new SS_HTMLValue($this->value);
|
||||
|
||||
// Populate link tracking for internal links & links to asset files.
|
||||
@ -89,13 +86,18 @@ class HtmlEditorField extends TextareaField {
|
||||
$link->setAttribute('class', preg_replace('/(^ss-broken|ss-broken$| ss-broken )/', null, $class));
|
||||
}
|
||||
|
||||
if($page = DataObject::get_by_id('SiteTree', $ID)) {
|
||||
$linkedPages[] = $page->ID;
|
||||
$linkedPages[] = $ID;
|
||||
if(!DataObject::get_by_id('SiteTree', $ID)) $record->HasBrokenLink = true;
|
||||
|
||||
} else if(substr($href, 0, strlen(ASSETS_DIR) + 1) == ASSETS_DIR.'/') {
|
||||
$candidateFile = File::find(Convert::raw2sql(urldecode($href)));
|
||||
if($candidateFile) {
|
||||
$linkedFiles[] = $candidateFile->ID;
|
||||
} else {
|
||||
$record->HasBrokenLink = true;
|
||||
$record->HasBrokenFile = true;
|
||||
}
|
||||
} elseif($href[0] != '/' && $file = File::find($href)) {
|
||||
$linkedFiles[] = $file->ID;
|
||||
} else if($href == '' || $href[0] == '/') {
|
||||
$record->HasBrokenLink = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -142,7 +144,9 @@ class HtmlEditorField extends TextareaField {
|
||||
DB::query("DELETE FROM \"$tracker->tableName\" WHERE $filter");
|
||||
|
||||
if($linkedPages) foreach($linkedPages as $item) {
|
||||
$tracker->add($item, array('FieldName' => $this->name));
|
||||
$SQL_fieldName = Convert::raw2sql($this->name);
|
||||
DB::query("INSERT INTO \"SiteTree_LinkTracking\" (\"SiteTreeID\",\"ChildID\", \"FieldName\")
|
||||
VALUES ($record->ID, $item, '$SQL_fieldName')");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class ClassInfoTest extends SapphireTest {
|
||||
|
||||
$classes = ClassInfo::classes_for_folder('sapphire/tests');
|
||||
$this->assertContains(
|
||||
'ClassInfoTest',
|
||||
'classinfotest',
|
||||
$classes,
|
||||
'ClassInfo::classes_for_folder() returns classes matching the filename'
|
||||
);
|
||||
|
@ -9,8 +9,8 @@ class ManifestBuilderTest extends SapphireTest {
|
||||
$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);
|
||||
global $project;
|
||||
|
||||
$this->assertEquals("$baseFolder/sapphire/MyClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['MyClass']);
|
||||
$this->assertEquals("$baseFolder/sapphire/subdir/SubDirClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['SubDirClass']);
|
||||
$this->assertEquals("$baseFolder/sapphire/MyClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['myclass']);
|
||||
$this->assertEquals("$baseFolder/sapphire/subdir/SubDirClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['subdirclass']);
|
||||
$this->assertNotContains('OtherFile', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
|
||||
$this->assertContains('MyClass', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists']));
|
||||
@ -38,12 +38,12 @@ class ManifestBuilderTest extends SapphireTest {
|
||||
$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);
|
||||
|
||||
/* Our fixture defines the class MyClass_InComment inside a comment, so it shouldn't be included in the class manifest. */
|
||||
$this->assertNotContains('MyClass_InComment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('myclass_incomment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('MyClass_InComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists']));
|
||||
$this->assertNotContains('MyClass_InComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents']));
|
||||
|
||||
/* Our fixture defines the class MyClass_InSlashSlashComment inside a //-style comment, so it shouldn't be included in the class manifest. */
|
||||
$this->assertNotContains('MyClass_InSlashSlashComment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('myclass_inslashslashcomment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('MyClass_InSlashSlashComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists']));
|
||||
$this->assertNotContains('MyClass_InSlashSlashComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents']));
|
||||
}
|
||||
@ -53,17 +53,17 @@ class ManifestBuilderTest extends SapphireTest {
|
||||
$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);
|
||||
|
||||
/* If a class defintion is listed in a single quote string, then it shouldn't be inlcuded. Here we have put a class definition for MyClass_InSingleQuoteString inside a single-quoted string */
|
||||
$this->assertNotContains('MyClass_InSingleQuoteString', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('myclass_insinglequotestring', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('MyClass_InSingleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists']));
|
||||
$this->assertNotContains('MyClass_InSingleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents']));
|
||||
|
||||
/* Ditto for double quotes. Here we have put a class definition for MyClass_InDoubleQuoteString inside a double-quoted string. */
|
||||
$this->assertNotContains('MyClass_InDoubleQuoteString', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('myclass_indoublequotestring', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('MyClass_InDoubleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists']));
|
||||
$this->assertNotContains('MyClass_InDoubleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents']));
|
||||
|
||||
/* Finally, we need to ensure that class definitions inside heredoc strings aren't included. Here, we have defined the class MyClass_InHeredocString inside a heredoc string. */
|
||||
$this->assertNotContains('MyClass_InHeredocString', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('myclass_inheredocstring', array_keys($manifestInfo['globals']['_CLASS_MANIFEST']));
|
||||
$this->assertNotContains('MyClass_InHeredocString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists']));
|
||||
$this->assertNotContains('MyClass_InHeredocString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['parents']));
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
|
||||
function testBrokenLinksBetweenPages() {
|
||||
$obj = $this->objFromFixture('Page','content');
|
||||
|
||||
$obj->Content = '<a href="no-page-here/">this is a broken link</a>';
|
||||
$obj->Content = '<a href="[sitetree_link id=3423423]">this is a broken link</a>';
|
||||
$obj->syncLinkTracking();
|
||||
$this->assertTrue($obj->HasBrokenLink, 'Page has a broken link');
|
||||
|
||||
$obj->Content = '<a href="about/">this is not a broken link</a>';
|
||||
$obj->Content = '<a href="[sitetree_link id=' . $this->idFromFixture('Page','about') .']">this is not a broken link</a>';
|
||||
$obj->syncLinkTracking();
|
||||
$this->assertFalse($obj->HasBrokenLink, 'Page does NOT have a broken link');
|
||||
}
|
||||
@ -107,10 +107,11 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
|
||||
$linkDest->doPublish();
|
||||
|
||||
$linkSrc = $this->objFromFixture('Page','content');
|
||||
$linkSrc->Content = "<p><a href=\"" . $linkDest->URLSegment . "/\">about us</a></p>";
|
||||
$linkSrc->Content = "<p><a href=\"[sitetree_link id=$linkDest->ID]\">about us</a></p>";
|
||||
$linkSrc->write();
|
||||
|
||||
$linkSrc->doPublish();
|
||||
|
||||
|
||||
// Confirm no broken link
|
||||
$this->assertEquals(0, (int)$linkSrc->HasBrokenLink);
|
||||
$this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\"
|
||||
@ -150,7 +151,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
|
||||
$linkDest->doDeleteFromLive();
|
||||
|
||||
$linkSrc = $this->objFromFixture('Page','content');
|
||||
$linkSrc->Content = "<p><a href=\"" . $linkDest->URLSegment . "/\">about us</a></p>";
|
||||
$linkSrc->Content = "<p><a href=\"[sitetree_link id=$linkDest->ID]\">about us</a></p>";
|
||||
$linkSrc->write();
|
||||
|
||||
// Publish the source of the link, while the dest is still unpublished.
|
||||
@ -174,7 +175,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
|
||||
// Content links are one kind of link to pages
|
||||
$p2 = new Page();
|
||||
$p2->Title = "regular link";
|
||||
$p2->Content = "<a href=\"" . Director::makeRelative($p->Link()) . "\">test</a>";
|
||||
$p2->Content = "<a href=\"[sitetree_link id=$p->ID]\">test</a>";
|
||||
$p2->write();
|
||||
$this->assertTrue($p2->doPublish());
|
||||
|
||||
@ -249,7 +250,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
|
||||
// Content links are one kind of link to pages
|
||||
$p2 = new Page();
|
||||
$p2->Title = "regular link";
|
||||
$p2->Content = "<a href=\"" . Director::makeRelative($p->Link()) . "\">test</a>";
|
||||
$p2->Content = "<a href=\"[sitetree_link id=$p->ID]\">test</a>";
|
||||
$p2->write();
|
||||
$this->assertTrue($p2->doPublish());
|
||||
|
||||
|
@ -151,6 +151,7 @@ class HtmlEditorFieldTest extends FunctionalTest {
|
||||
'<p><a href="[sitetree_link id=%d]">Working Link</a></p>',
|
||||
$this->idFromFixture('SiteTree', 'home')
|
||||
));
|
||||
$sitetree->HasBrokenLink = false;
|
||||
$editor->saveInto($sitetree);
|
||||
|
||||
$this->assertFalse((bool) $sitetree->HasBrokenLink);
|
||||
|
Loading…
x
Reference in New Issue
Block a user