Skip to content
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

Add dkan linkchecker feature #2339

Merged
merged 4 commits into from
Apr 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .ahoy/.scripts/dkan-lint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'json'
require 'uri'
require 'net/http'
require 'fileutils'
require 'git'

include FileUtils
include Git

# Get the list of files from a PR
def get_pr_files(user, repo, pr)
uri = URI.parse("https://api.github.com/repos/#{user}/#{repo}/pulls/#{pr}/files")

http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
http.use_ssl = true
response = http.request(request)
result = JSON.parse(response.body)
files = Array.new

result.each do |i|
files.push(i['filename'])
end

return files
end

if 1==1
user = 'GetDKAN'
repo = 'dkan'
pr = '2454'
files = get_pr_files(user, repo, pr)
elsif ARGV.any?
files = ARGV
else
FileUtils.cd 'dkan'
g = Git.open('.')
files = g.diff.name_status.select{|k,v| v != "D"}.keys
FileUtils.cd '..'
end

if files.any?
# Filter file list for approved file types
files.select!{ |i| i[/\.*(\.php|\.inc|\.module|\.install|\.profile|\.info)$/] }
if files.any?
files.map! {|item| 'dkan/' + item}
puts "Linting files:\n" + files.join("\n")
puts `dkan/test/bin/phpcs --standard=Drupal,DrupalPractice -n --ignore=test/dkanextension/*,patches/* #{files.join(" ")}`
else
puts "No files available to lint; ending."
end
end
26 changes: 0 additions & 26 deletions .ahoy/.scripts/dkan-lint.sh

This file was deleted.

8 changes: 6 additions & 2 deletions .ahoy/dkan.ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ commands:
cmd: ahoy cmd-proxy bash dkan/.ahoy/.scripts/dkan-unittests.sh "{{args}}"

lint:
usage: Run linter on code
usage: Run linter on DKAN code
hidden: true
cmd: ahoy cmd-proxy bash dkan/.ahoy/.scripts/dkan-lint.sh "{{args}}"
cmd: |
ahoy cmd-proxy gem install git
ahoy cmd-proxy bash dkan/.ahoy/.scripts/composer-install.sh dkan/test
ahoy cmd-proxy dkan/test/bin/phpcs --config-set installed_paths dkan/test/vendor/drupal/coder/coder_sniffer
ahoy cmd-proxy ruby dkan/.ahoy/.scripts/dkan-lint.rb {{args}}

create-qa-users:
usage: Create users for each core role for QA purposes
Expand Down
10 changes: 6 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ jobs:
command: sudo apt-get update
- run:
name: Install Packages
command: sudo apt-get install -y ruby libpng-dev libmcrypt-dev mysql-client x11vnc
command: |
sudo apt-get install -y ruby libpng-dev libmcrypt-dev mysql-client x11vnc
sudo gem install git

#Available Extensions:
#bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt mssql mysql mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets spl standard sybase_ct sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip
Expand Down Expand Up @@ -118,16 +120,16 @@ jobs:
key: v1-dkan-test-vendor
paths:
- dkan/test/vendor
- run:
name: Run Parallel Behat Tests
command: ruby dkan/.ahoy/.scripts/circle-behat.rb docroot/profiles/dkan/test/features
# Lint only on 1st parallel instance. Deploy: blocks until parallelism is done, so doing it this way.
- run:
name: Run Lint
command: |
if [ "$CIRCLE_NODE_INDEX" -eq "0" ]; then
ahoy dkan lint
fi
- run:
name: Run Parallel Behat Tests
command: ruby dkan/.ahoy/.scripts/circle-behat.rb docroot/profiles/dkan/test/features
# Unit Tests only on 1st parallel instance. Deploy: blocks until parallelism is done, so doing it this way.
- run:
name: Run PHPUnit Tests
Expand Down
1 change: 1 addition & 0 deletions docs/components/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ described inside the Datasets section, all this functionality is provided by the
Storytelling <storytelling>
Open Data Schema Map <open-data-schema>
Visualizations <visualizations/index>
Link checker <linkchecker>

.. note:: The three modules mentioned above that are not distributed with DKAN
continue to be maintained in separate repositories because they work
Expand Down
26 changes: 26 additions & 0 deletions docs/components/linkchecker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
DKAN Link Checker
=================

DKAN Link Checker adds configuration and additional reporting to the `link checker <https://www.drupal.org/project/linkchecker>`_ module.

The Link checker module extracts links from your content when saved and periodically tries to detect broken hypertext links by checking the remote sites and evaluating the HTTP response codes.

Installation
------------
DKAN Link checker will check links in datasets, resources, and harvest sources. It is not enabled by default, to enable it, run these commands:

- ``drush en dkan_linkchecker -y``
- ``drush cc all``
- ``drush linkchecker-analyze``
- ``drush cron``

Links will be processed in batches and it may take a while to go through all of the links of your site.

Permissions
-----------
Users with the **site manager** role will be able to

- View the broken links report at ``admin/reports/dkan-linkchecker-report``
- Access the link checker configuration screen at ``admin/config/content/linkchecker``

For more information on link checker `click here <https://cgit.drupalcode.org/linkchecker/tree/README.txt?h=7.x-1.x>`_
8 changes: 8 additions & 0 deletions drupal-org.make
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ projects:
version: '1.1'
link_iframe_formatter:
version: '1.1'
linkchecker:
download:
type: git
url: 'https://git.drupal.org/project/linkchecker.git'
revision: 623819d04464b26af8e216113a88cd03f4bb4ccc
patch:
965720: https://www.drupal.org/files/issues/linkchecker-views-integration-965720-124.patch
1: patches/dkan_linkchecker_file.patch
manualcrop:
version: '1.6'
markdown:
Expand Down
21 changes: 21 additions & 0 deletions modules/dkan/dkan_linkchecker/css/linkchecker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.view-dkan-linkchecker-reports {
font-family: arial;
font-size: 12px;
font-weight: normal;
}
.view-dkan-linkchecker-reports .views-exposed-form .views-exposed-widget {
padding-top: 0;
}
.view-dkan-linkchecker-reports th.views-field-nothing {
text-align: center;
}
.view-dkan-linkchecker-reports td.views-field-nothing a:hover {
text-decoration: none;
}
.view-dkan-linkchecker-reports td.views-field-nothing a .btn-primary {
margin: 2px;
padding: 4px 8px;
}
.view-dkan-linkchecker-reports .views-field i {
font-size: 1.5em;
}
22 changes: 22 additions & 0 deletions modules/dkan/dkan_linkchecker/dkan_linkchecker.features.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @file
* dkan_linkchecker.features.inc
*/

/**
* Implements hook_ctools_plugin_api().
*/
function dkan_linkchecker_ctools_plugin_api($module = NULL, $api = NULL) {
if ($module == "strongarm" && $api == "strongarm") {
return array("version" => "1");
}
}

/**
* Implements hook_views_api().
*/
function dkan_linkchecker_views_api($module = NULL, $api = NULL) {
return array("api" => "3.0");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* @file
* dkan_linkchecker.features.user_permission.inc
*/

/**
* Implements hook_user_default_permissions().
*/
function dkan_linkchecker_user_default_permissions() {
$permissions = array();

if (module_exists('linkchecker')) {
// Exported permission: 'access broken links report'.
$permissions['access broken links report'] = array(
'name' => 'access broken links report',
'roles' => array(
'site manager' => 'site manager',
),
'module' => 'linkchecker',
);

// Exported permission: 'access own broken links report'.
$permissions['access own broken links report'] = array(
'name' => 'access own broken links report',
'roles' => array(
'site manager' => 'site manager',
),
'module' => 'linkchecker',
);

// Exported permission: 'administer linkchecker'.
$permissions['administer linkchecker'] = array(
'name' => 'administer linkchecker',
'roles' => array(
'site manager' => 'site manager',
),
'module' => 'linkchecker',
);

// Exported permission: 'edit link settings'.
$permissions['edit link settings'] = array(
'name' => 'edit link settings',
'roles' => array(
'site manager' => 'site manager',
),
'module' => 'linkchecker',
);
}

return $permissions;
}
24 changes: 24 additions & 0 deletions modules/dkan/dkan_linkchecker/dkan_linkchecker.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name = DKAN Link Checker
description = Checks for broken links in datasets, resources, and harvest sources.
core = 7.x
package = DKAN
dependencies[] = dkan_sitewide_menu
dependencies[] = features
dependencies[] = linkchecker
dependencies[] = menu
dependencies[] = strongarm
dependencies[] = views
features[ctools][] = strongarm:strongarm:1
features[ctools][] = views:views_default:3.0
features[features_api][] = api:2
features[user_permission][] = access broken links report
features[user_permission][] = access own broken links report
features[user_permission][] = administer linkchecker
features[user_permission][] = edit link settings
features[variable][] = linkchecker_check_links_types
features[variable][] = linkchecker_scan_node_dataset
features[variable][] = linkchecker_scan_node_harvest_source
features[variable][] = linkchecker_scan_node_resource
features[views_view][] = dkan_linkchecker_reports
features_exclude[dependencies][ctools] = ctools
project path = profiles/dkan/modules/dkan
17 changes: 17 additions & 0 deletions modules/dkan/dkan_linkchecker/dkan_linkchecker.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @file
* Additional setup tasks for DKAN Link Checker.
*/

/**
* Implements hook_enable().
*/
function dkan_linkchecker_enable() {
// Disable the standard linkchecker_reports view to avoid confusion.
$list = variable_get('views_defaults');
$n = array('linkchecker_reports' => TRUE);
$disabled = array_merge($list, $n);
variable_set('views_defaults', $disabled);
}
Loading