Version: current

     1 <?php
     2 /*
     3  * Задача поиска выпавших с сайта при конвертации (2.6 -> 3.1) ссылок
     4  * Сохраняет выпавшие ссылки в файл bad_urls.txt во временной папке конвертации
     5  *
     6  * @author menedem
     7  */
     8 class FindBadLinksTask extends BuildTask {
     9     function run($request) {
    10         if (!Director::is_cli() && !Permission::check("ADMIN") ) {
    11             print "Permission denied";
    12             return;
    13         }
    14         $siteName = $request->getVar('site');
    15         $oldSiteMap = simplexml_load_file("http://" . $siteName . '/sitemap.cgi');
    16         $handle = @fopen(ConvertFrom26Task::base_dir() . '/url_map.txt', "r");
    17         $map = array();
    18         if ($handle) {
    19             while (($buffer = fgets($handle)) !== false) {
    20                 $map[] = explode(' ', $buffer);
    21             }
    22             if (!feof($handle)) {
    23                 die("Error: unexpected fgets() fail\n");
    24             }
    25             fclose($handle);
    26         }
    27
    28         $lines = "";
    29         foreach($oldSiteMap->url as $url) {
    30             $urlData = parse_url($url->loc);
    31             foreach($map as $entry) {
    32                 $urlPath = $urlData['path'];
    33                 if ($entry[0] == $urlPath) {
    34                     $urlPath = $entry[1];
    35                     break;
    36                 }
    37             }
    38             if (!@file_get_contents(Director::absoluteURL(trim($urlPath)))) {
    39                 $lines .= Director::absoluteURL(trim($urlPath)) . " \n";
    40             }
    41         }
    42         if ($lines) {
    43             file_put_contents(ConvertFrom26Task::base_dir() . '/bad_urls.txt', $lines);
    44         }
    45     }
    46 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -