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

Added standard .editorconfig file #4

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3b976fd
NEW: Adding link tracking css class and using built in reporting
kmayo-ss Jul 22, 2014
72dc652
NEW: Setting up Queued job and task to support being sent a single page
kmayo-ss Jul 24, 2014
a3c6931
NEW: Adding back in the Broken links model no model admin this time t…
kmayo-ss Jul 24, 2014
bb30288
NEW: Adding report link to setup new queued job
kmayo-ss Jul 27, 2014
d25adca
NEW: Adding tests and code tidyup
kmayo-ss Jul 28, 2014
093322f
NEW: Adding a option to run a batch job to the front end
kmayo-ss Jul 30, 2014
564514b
NEW: Adding whitelisted codes via yml
kmayo-ss Jul 30, 2014
e9fe1a4
NEW: Use DB row for job status and refactor the sql statements
kmayo-ss Jul 31, 2014
9e5a41f
NEW: Fixing queuedjob status and hiding report button when report is …
kmayo-ss Aug 3, 2014
363ecd4
Make sure that process yields to queuedjobs after each page
Aug 3, 2014
5a1c636
Merge pull request #3 from tractorcow/pulls/fix-tmp-loop
kmayo-ss Aug 3, 2014
da7e45d
BUG: Fixing report page link and set to check stage not live
kmayo-ss Aug 4, 2014
6bda4dc
BUG: Correcting test code and fixing bug with create report button
kmayo-ss Aug 4, 2014
f55a650
NEW: Plat-59 Do not display broken previous report info for the lates…
kmayo-ss Aug 6, 2014
a4ede24
Tests, refactor, cleanup, fix issues
Aug 7, 2014
ec4c479
Update travis, composer, license
Aug 7, 2014
1fb59f9
Fix incorrect function visibility
Aug 12, 2014
7328344
API Add description for response code to report
Aug 12, 2014
1aa5491
Update docs
Aug 12, 2014
7698ba9
Merge pull request #2 from tractorcow/pulls/docs
halkyon Aug 12, 2014
d9e1b99
Merge pull request #1 from tractorcow/pulls/description
halkyon Aug 12, 2014
486ccec
Fixing CurlLinkChecker::checkLink() using incorrect visibility
Aug 13, 2014
a283b6b
Merge pull request #3 from halkyon/visibility_info
Aug 13, 2014
aef8f6f
Fixing CSV export columns to match the ones show in broken links report
Aug 13, 2014
606c801
Merge pull request #4 from halkyon/export_csv_columns
Aug 13, 2014
3431448
Fixing static visibility and moving method to underneath statics
Aug 13, 2014
5a4682c
Merge pull request #5 from halkyon/method_vis
Aug 13, 2014
2a3f99b
Removing unused static funcs and moving existing statics to top of cl…
Aug 13, 2014
2a286fd
Merge pull request #6 from halkyon/vis_changes
Aug 13, 2014
65117b2
BUG Indicator stuck on 0% until you refresh the page.
Aug 13, 2014
f2b4c7b
Merge pull request #7 from halkyon/indicator_fixes
Aug 13, 2014
a35241c
Update translations
Nov 18, 2014
38659ba
Include Hamcrest without clashing with PHPUnit globals
chillu Apr 29, 2015
b219ebb
Merge pull request #8 from silverstripe-labs/pulls/avoid-hamcrest-glo…
May 27, 2015
4411d2e
Move to new travis containerised infrastructure
dhensby Jul 20, 2015
c949b12
Merge pull request #9 from dhensby/patch-2
Jul 21, 2015
928f604
Include tests for 3.2 and php 5.6
Oct 30, 2015
f0134c9
Merge pull request #10 from silverstripe-labs/pulls/travis
chillu Nov 1, 2015
c37a13b
PL translation added
mikron-ia Nov 6, 2015
821d86a
Merge pull request #11 from mikron-ia/translation-pl
Nov 15, 2015
0531d69
Add module to transifex
Nov 15, 2015
929bf30
Release 1.0.3
Nov 19, 2015
97c3623
Merge pull request #16 from tractorcow/pulls/release-103
scott1702 Nov 19, 2015
638844b
Added standard code of conduct
Nov 21, 2015
79a4e69
Merge pull request #19 from helpfulrobot/add-standard-code-of-conduct
Nov 26, 2015
14ccb2a
Added standard .editorconfig file
Dec 16, 2015
fe8d93c
Merge pull request #20 from helpfulrobot/add-standard-editorconfig-file
Dec 17, 2015
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
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# For more information about the properties used in this file,
# please see the EditorConfig documentation:
# http://editorconfig.org

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.yml,package.json}]
indent_size = 2

# The indent size used in the package.json file cannot be changed:
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: php

sudo: false

php:
- 5.3

env:
- DB=MYSQL CORE_RELEASE=3.1

matrix:
include:
- php: 5.4
env: DB=PGSQL CORE_RELEASE=3.1
- php: 5.5
env: DB=MYSQL CORE_RELEASE=3
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3.2

before_script:
- composer self-update || true
- phpenv rehash
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss

script:
- vendor/bin/phpunit externallinks/tests
8 changes: 8 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[main]
host = https://www.transifex.com

[silverstripe-externallinks.master]
file_filter = lang/<lang>.yml
source_file = lang/en.yml
source_lang = en
type = YML
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.3]

* Changelog added.
* Update translations.
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
* Copyright (c) 2014, Silverstripe Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Silverstripe Ltd. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Silverstripe Ltd. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71 changes: 52 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,82 @@
# External links

[![Build Status](https://travis-ci.org/silverstripe-labs/silverstripe-externallinks.svg?branch=master)](https://travis-ci.org/silverstripe-labs/silverstripe-externallinks)

## Introduction

The external links module is a task and ModelAdmin to track and to report on broken external links.

## Maintainer Contact

* Kirk Mayo kirk (at) silverstripe (dot) com
* Damian Mooyman (@tractorcow) <damian@silverstripe.com>

## Requirements

* SilverStripe 3.0 +
* SilverStripe 3.1 +

## Features

* Add external links to broken links reports
* Add a model admin for external broken links
* Add a task to track external broken links

See the [changelog](CHANGELOG.md) for version history.

## Installation

1. Download the module form GitHub (Composer support to be added)
2. Extract the file (if you are on windows try 7-zip for extracting tar.gz files
3. Make sure the folder after being extracted is named 'externallinks'
4. Place this directory in your sites root directory. This is the one with framework and cms in it.
5. Run in your browser - `/dev/build` to rebuild the database.
6. You should see a new menu called *Broken Ext. Links*
7. Run the following task *http://path.to.silverstripe/dev/tasks/CheckExternalLinks* to check for broken external links
1. If you have composer you can use `composer require silverstripe/externallinks:*`. Otherwise,
download the module from GitHub and extract to the 'externallinks' folder. Place this directory
in your sites root directory. This is the one with framework and cms in it.
2. Run in your browser - `/dev/build` to rebuild the database.
3. Run the following task *http://path.to.silverstripe/dev/tasks/CheckExternalLinks* to check for
broken external links

## Report ##

A new report is added called 'External Broken links report'. When viewing this report, a user may press
the "Create new report" button which will trigger an ajax request to initiate a report run.

In this initial ajax request this module will do one of two things, depending on which modules are included:

* If the queuedjobs module is installed, a new queued job will be initiated. The queuedjobs module will then
manage the progress of the task.
* If the queuedjobs module is absent, then the controller will fallback to running a buildtask in the background.
This is less robust, as a failure or error during this process will abort the run.

In either case, the background task will loop over every page in the system, inspecting all external urls and
checking the status code returned by requesting each one. If a URL returns a response code that is considered
"broken" (defined as < 200 or > 302) then the `ss-broken` css class will be assigned to that url, and
a line item will be added to the report. If a previously broken link has been corrected or fixed, then
this class is removed.

In the actual report generated the user can click on any broken link item to either view the link in their browser,
or edit the containing page in the CMS.

While a report is running the current status of this report will be displayed on the report details page, along
with the status. The user may leave this page and return to it later to view the ongoing status of this report.

Any subsequent report may not be generated until a prior report has completed.

## Dev task ##

Run the following task *http://path.to.silverstripe/dev/tasks/CheckExternalLinks* to check your site for external
broken links.
If you have the queuedjobs module installed you can set the task to be run every so ofter
Add the following code to the mysite config to run the job every 24 hours (86400 seconds)

`Config::inst()->update('CheckExternalLinks', 'QueuedJob', 86400);`

## Queued job ##

## Disable the Broken external link menu
If you have the queuedjobs module installed you can set the task to be run every so ofter
Add the following yml config to config.yml in mysite/_config have the the task run once every day (86400 seconds)

To disable the *Broken Ext. Links* menu add the following code to mysite/_config.php
CheckExternalLinks:
Delay: 86400

`CMSMenu::remove_menu_item('BrokenExternalLinksAdmin');`
## Whitelisting codes ##

## TODO ##
If you want to ignore or whitelist certain http codes this can be setup via IgnoreCodes in the config.yml
file in mysite/_config

Fix setting the class attribute of broken links to ss-broken
CheckExternalLinks:
Delay: 60
IgnoreCodes:
- 401
- 403
- 501
1 change: 0 additions & 1 deletion _config.php

This file was deleted.

5 changes: 5 additions & 0 deletions _config/injector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
Name: externallinksdependencies
---
Injector:
LinkChecker: CurlLinkChecker
7 changes: 7 additions & 0 deletions _config/routes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
Name: externallink
After: framework/routes
---
Director:
rules:
'admin/externallinks//$Action': 'CMSExternalLinks_Controller'
1 change: 1 addition & 0 deletions code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When having discussions about this module in issues or pull request please adhere to the [SilverStripe Community Code of Conduct](https://docs.silverstripe.org/en/contributing/code_of_conduct).
54 changes: 54 additions & 0 deletions code/controllers/CMSExternalLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

class CMSExternalLinks_Controller extends Controller {

private static $allowed_actions = array('getJobStatus', 'start');

/*
* Respond to Ajax requests for info on a running job
*
* @return string JSON string detailing status of the job
*/
public function getJobStatus() {
// Set headers
HTTP::set_cache_age(0);
HTTP::add_cache_headers($this->response);
$this->response
->addHeader('Content-Type', 'application/json')
->addHeader('Content-Encoding', 'UTF-8')
->addHeader('X-Content-Type-Options', 'nosniff');

// Format status
$track = BrokenExternalPageTrackStatus::get_latest();
if($track) return json_encode(array(
'TrackID' => $track->ID,
'Status' => $track->Status,
'Completed' => $track->getCompletedPages(),
'Total' => $track->getTotalPages()
));
}


/*
* Starts a broken external link check
*/
public function start() {
// return if the a job is already running
$status = BrokenExternalPageTrackStatus::get_latest();
if ($status && $status->Status == 'Running') return;

// Create a new job
if (class_exists('QueuedJobService')) {
// Force the creation of a new run
BrokenExternalPageTrackStatus::create_status();
$checkLinks = new CheckExternalLinksJob();
singleton('QueuedJobService')->queueJob($checkLinks);
} else {
//TODO this hangs as it waits for the connection to be released
// should return back and continue processing
// http://us3.php.net/manual/en/features.connection-handling.php
$task = CheckExternalLinksTask::create();
$task->runLinksCheck();
}
}
}
70 changes: 13 additions & 57 deletions code/jobs/CheckExternalLinksJob.php
Original file line number Diff line number Diff line change
@@ -1,78 +1,34 @@
<?php

if(!class_exists('AbstractQueuedJob')) return;

/**
* An check external links job
* A Job for running a external link check for published pages
*
*/
class CheckExternalLinksJob extends AbstractQueuedJob {

public static $regenerate_time = 43200;
class CheckExternalLinksJob extends AbstractQueuedJob implements QueuedJob {

public function __construct() {
$this->pagesToProcess = DB::query('SELECT "ID" FROM "SiteTree_Live" WHERE "ShowInSearch"=1')->column();
$this->currentStep = 0;
$this->totalSteps = count($this->pagesToProcess);
public function getTitle() {
return _t('CheckExternalLiksJob.TITLE', 'Checking for external broken links');
}

/**
* Sitemap job is going to run for a while...
*/
public function getJobType() {
return QueuedJob::QUEUED;
}

/**
* @return string
*/
public function getTitle() {
return 'Checking external links';
}

/**
* Return a signature for this queued job
*
* For the generate sitemap job, we only ever want one instance running, so just use the class name
*
* @return String
*/
public function getSignature() {
return md5(get_class($this));
}

/**
* Note that this is duplicated for backwards compatibility purposes...
* Check an individual page
*/
public function setup() {
parent::setup();
increase_time_limit_to();

$restart = $this->currentStep == 0;

if ($restart) {
$this->pagesToProcess = DB::query('SELECT "ID" FROM SiteTree_Live WHERE ShowInSearch=1')->column();
}
}

/**
* On any restart, make sure to check that our temporary file is being created still.
*/
public function prepareForRestart() {
parent::prepareForRestart();
}

public function process() {
$task = new CheckExternalLinks();
$task->run();
$this->completeJob();
$task = CheckExternalLinksTask::create();
$track = $task->runLinksCheck(1);
$this->currentStep = $track->CompletedPages;
$this->totalSteps = $track->TotalPages;
$this->isComplete = $track->Status === 'Completed';
}

/**
* Outputs the completed file to the site's webroot
*/
protected function completeJob() {
$this->isComplete = 1;
$nextgeneration = new CheckExternalLinksJob();
singleton('QueuedJobService')->queueJob($nextgeneration,
date('Y-m-d H:i:s', time() + self::$regenerate_time));
}
}
}
Loading