From 2ac279a981e6ca77b50971de94a86a36f3464e44 Mon Sep 17 00:00:00 2001
From: Colan Schwartz <colan@58704.no-reply.drupal.org>
Date: Thu, 25 Feb 2016 11:32:39 -0500
Subject: [PATCH] Issue #2066371 by codi, FluxSauce, colan: Allow use without
 module installation.

---
 hacked.drush.inc  | 26 +++++++++++++++++++-------
 hacked.report.inc |  5 +++--
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/hacked.drush.inc b/hacked.drush.inc
index 161c667..15fb2aa 100644
--- a/hacked.drush.inc
+++ b/hacked.drush.inc
@@ -36,7 +36,6 @@ function hacked_drush_command() {
 
   $items['hacked-list-projects'] = array(
     'description' => "List all projects that can be analysed by Hacked! ",
-    'drupal dependencies' => array('hacked'),
     'options' => array(
       'force-rebuild' => 'Rebuild the Hacked! report instead of getting a cached version.'
     ),
@@ -45,12 +44,10 @@ function hacked_drush_command() {
 
   $items['hacked-lock-modified'] = array(
     'description' => "Lock all projects that Hacked! detects are modified, so that drush pm-updatecode will not touch them. (drush-4.x+ only)",
-    'drupal dependencies' => array('hacked'),
   );
 
   $items['hacked-details'] = array(
     'description' => "Show the Hacked! report about a specific project.",
-    'drupal dependencies' => array('hacked'),
     'arguments' => array(
       'project' => 'The machine name of the project to report on.',
     ),
@@ -62,7 +59,6 @@ function hacked_drush_command() {
 
   $items['hacked-diff'] = array(
     'description' => "Output a unified diff of the project specified.",
-    'drupal dependencies' => array('hacked'),
     'arguments' => array(
       'project' => 'The machine name of the project to report on.',
     ),
@@ -81,6 +77,7 @@ function hacked_drush_command() {
  * So you'll want to be very careful if you call this!
  */
 function hacked_calculate_project_data_drush($projects, $force = FALSE, $redirect = NULL) {
+  hacked_load_dependencies();
   include_once DRUPAL_ROOT . '/core/includes/batch.inc';
 
   // Try to get the report form cache if we can.
@@ -101,7 +98,7 @@ function hacked_calculate_project_data_drush($projects, $force = FALSE, $redirec
   $batch = array(
     'operations' => $operations,
     'finished' => 'hacked_build_report_batch_finished_drush',
-    'file' => drupal_get_path('module', 'hacked') . '/hacked.report.inc',
+    'file' => drush_get_command()['path'] . '/hacked.report.inc',
     'title' => t('Building report'),
   );
 
@@ -135,6 +132,7 @@ function hacked_build_report_batch_finished_drush($success, $results, $operation
  * Drush command callback that shows the listing of changed/unchanged projects.
  */
 function drush_hacked_list_projects() {
+  hacked_load_dependencies();
 
   // Go get the data:
   module_load_include('inc', 'update', 'update.report');
@@ -379,7 +377,21 @@ function drush_hacked_diff($short_name) {
     }
 
     drush_print($line);
-
   }
-
 }
+
+/**
+ * Allow Hacked! to be used without being enabled, like a drush command
+ * installed on a platform.
+ */
+function hacked_load_dependencies() {
+  if (!\Drupal::moduleHandler()->moduleExists('hacked')) {
+    // Get the command path.
+    $path = drush_get_command()['path'];
+
+    // Use it to include missing dependencies.
+    include_once $path . '/hacked.module';
+    include_once $path . '/src/hackedProject.php';
+    include_once $path . '/hacked.report.inc';
+  }
+}
\ No newline at end of file
diff --git a/hacked.report.inc b/hacked.report.inc
index 862e7ca..b69eb4c 100644
--- a/hacked.report.inc
+++ b/hacked.report.inc
@@ -9,11 +9,12 @@ use Drupal\hacked\hackedProject;
  * Batch callback to build the hacked report.
  */
 function hacked_build_report_batch($project_name, &$context) {
+  hacked_load_dependencies();
+
   if (!isset($context['results']['report'])) {
     $context['results']['report'] = array();
   }
-  \Drupal::moduleHandler()
-    ->loadInclude('hacked', 'inc', 'includes/hacked_project');
+
   $project = new hackedProject($project_name);
   $context['results']['report'][$project_name] = $project->compute_report();
   $context['message'] = t('Finished processing: @name', array('@name' => $project->title()));
-- 
2.5.0

