Skip to content

Commit

Permalink
src: adding plugin AddToRobots so I can run in drush
Browse files Browse the repository at this point in the history
  • Loading branch information
protitude committed Jan 2, 2023
1 parent 9e4a511 commit f7ff5a6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
18 changes: 3 additions & 15 deletions oit_dev.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use Drupal\servicenow\Plugin\ServicenowUserLookup;
use Drupal\oit_dev\Plugin\AddToRobots;

/**
* Implements hook_install().
Expand Down Expand Up @@ -38,21 +39,8 @@ function oit_dev_install() {
$this_user->set('field_service_meow_dds_pod_group', $pod_group);
$this_user->save();
}
// Pull in archived news to add to add to robots.txt
$news_archive = \Drupal::entityQuery('node');
$news_archive->condition('field_news_archive', 3);
$news_results = $news_archive->execute();
$news_archive_string = "# Paths OIT\n";
$news_archive_string .= "Disallow: /taxonomy/term/*\n";
$news_archive_string .= "Disallow: /node?page=*\n";
$news_archive_string .= "Disallow: /tutorial/hotmail-configure-outlook-windows?page=2\n";
$news_archive_string .= "Disallow: /tutorial/hotmail-configure-outlook-windows?page=3\n";
$news_archive_string .= "Disallow: /it-security/email-phishing/*\n";
$news_archive_string .= "# Archived news nodes\n";
foreach ($news_results as $news_result) {
$news_archive_string .= "Disallow: /node/$news_result\n";
}
file_put_contents('../add-to-robots.txt', $news_archive_string);
// Pull in archived news to add to add to robots.txt.
new AddToRobots();
}

/**
Expand Down
31 changes: 31 additions & 0 deletions src/Plugin/AddToRobots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Drupal\oit_dev\Plugin;

/**
* Create file to add to robots.txt.
*/
class AddToRobots {

/**
* Function to pull in archived news to add to add to robots.txt.
*/
public function __construct() {
$news_archive = \Drupal::entityQuery('node');
$news_archive->condition('field_news_archive', 3);
$news_results = $news_archive->execute();
$news_archive_string = "# Paths OIT\n";
$news_archive_string .= "Disallow: /taxonomy/term/*\n";
$news_archive_string .= "Disallow: /node?page=*\n";
$news_archive_string .= "Disallow: /tutorial/hotmail-configure-outlook-windows?page=2\n";
$news_archive_string .= "Disallow: /tutorial/hotmail-configure-outlook-windows?page=3\n";
$news_archive_string .= "Disallow: /it-security/email-phishing/*\n";
$news_archive_string .= "# Archived news nodes\n";
foreach ($news_results as $news_result) {
$news_archive_string .= "Disallow: /node/$news_result\n";
}
file_put_contents('../add-to-robots.txt', $news_archive_string);
return 'Created maybe';
}

}

0 comments on commit f7ff5a6

Please sign in to comment.