Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
linkchecker-3247797
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
linkchecker-3247797
Commits
6f263d32
Commit
6f263d32
authored
5 years ago
by
Jeroen Tubex
Committed by
Carsten Logemann
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3065028
by JeroenT, dexiecarla, Znak: Cannot clear link data and analyze content for links
parent
676c0d7d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/LinkCleanUp.php
+22
-3
22 additions, 3 deletions
src/LinkCleanUp.php
tests/src/Kernel/LinkcheckerCleanUpTest.php
+105
-0
105 additions, 0 deletions
tests/src/Kernel/LinkcheckerCleanUpTest.php
with
127 additions
and
3 deletions
src/LinkCleanUp.php
+
22
−
3
View file @
6f263d32
...
...
@@ -6,12 +6,18 @@ use Drupal\Core\Batch\BatchBuilder;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Entity\FieldableEntityInterface
;
use
Drupal\Core\DependencyInjection\DependencySerializationTrait
;
use
Drupal\Core\Messenger\MessengerTrait
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
/**
* Class LinkCleanUp.
*/
class
LinkCleanUp
{
use
DependencySerializationTrait
;
use
MessengerTrait
;
use
StringTranslationTrait
;
/**
* The entity type manager.
*
...
...
@@ -51,12 +57,11 @@ class LinkCleanUp {
$batch
=
new
BatchBuilder
();
$batch
->
setTitle
(
'Remove links'
)
->
addOperation
([
$this
,
'
p
rocessDelete'
])
->
addOperation
([
$this
,
'
batchP
rocessDelete'
])
->
setProgressive
()
->
setFinishCallback
([
$this
,
'batchFinished'
]);
batch_set
(
$batch
->
toArray
());
}
/**
...
...
@@ -150,4 +155,18 @@ class LinkCleanUp {
}
}
/**
* Finished callback for batch.
*/
public
function
batchFinished
(
$success
)
{
if
(
$success
)
{
$this
->
messenger
()
->
addStatus
(
$this
->
t
(
'Links were successfully checked.'
));
}
else
{
$this
->
messenger
()
->
addError
(
$this
->
t
(
'Links were not checked.'
));
}
}
}
This diff is collapsed.
Click to expand it.
tests/src/Kernel/LinkcheckerCleanUpTest.php
0 → 100644
+
105
−
0
View file @
6f263d32
<?php
namespace
Drupal\Tests\linkchecker\Kernel
;
use
Drupal\KernelTests\KernelTestBase
;
use
Drupal\linkchecker\Entity\LinkCheckerLink
;
/**
* Test for linkchecker.clean_up service.
*
* @coversDefaultClass \Drupal\linkchecker\LinkCleanUp
*
* @group linkchecker
*/
class
LinkcheckerCleanUpTest
extends
KernelTestBase
{
/**
* {@inheritdoc}
*/
public
static
$modules
=
[
'system'
,
'linkchecker'
,
'dynamic_entity_reference'
,
];
/**
* The link clean up service.
*
* @var \Drupal\linkchecker\LinkCleanUp
*/
protected
$linkCleanUp
;
/**
* The link checker link storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected
$linkCheckerLinkStorage
;
/**
* {@inheritdoc}
*/
public
function
setUp
()
{
parent
::
setUp
();
$this
->
installSchema
(
'system'
,
'sequences'
);
$this
->
installEntitySchema
(
'linkcheckerlink'
);
$this
->
installConfig
(
'linkchecker'
);
$this
->
linkCleanUp
=
$this
->
container
->
get
(
'linkchecker.clean_up'
);
$this
->
linkCheckerLinkStorage
=
$this
->
container
->
get
(
'entity_type.manager'
)
->
getStorage
(
'linkcheckerlink'
)
;
}
/**
* @covers ::removeAllBatch
*/
public
function
testRemoveAllBatch
()
{
$urls
=
[
'https://existing.com'
,
'https://not-existing.com'
,
'https://example.com/existing'
,
];
foreach
(
$urls
as
$url
)
{
$this
->
createDummyLink
(
$url
);
}
$this
->
assertCount
(
3
,
$this
->
linkCheckerLinkStorage
->
loadMultiple
(
NULL
));
$this
->
linkCleanUp
->
removeAllBatch
();
$this
->
runBatch
();
$this
->
assertEmpty
(
$this
->
linkCheckerLinkStorage
->
loadMultiple
(
$this
->
linkCheckerLinkStorage
->
loadMultiple
(
NULL
)));
}
/**
* Helper function for link creation.
*/
protected
function
createDummyLink
(
$url
)
{
$link
=
LinkCheckerLink
::
create
([
'url'
=>
$url
,
'entity_id'
=>
[
'target_id'
=>
1
,
'target_type'
=>
'dummy_type'
,
],
'entity_field'
=>
'dummy_field'
,
'entity_langcode'
=>
'en'
,
]);
$link
->
save
();
return
$link
;
}
/**
* Runs the currently set batch, if any exists.
*/
protected
function
runBatch
()
{
$batch
=
&
batch_get
();
if
(
$batch
)
{
$batch
[
'progressive'
]
=
FALSE
;
batch_process
();
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment