From 61e1e4c2f961d854ad8dc679f58174eacdaf940a Mon Sep 17 00:00:00 2001
From: Matt Westcott <matt@west.co.tt>
Date: Fri, 25 Jan 2019 14:48:22 +0000
Subject: [PATCH] Add 'wagtail_update_index' as an alias for the 'update_index'
 command (#5009)

Fixes #2447
---
 CHANGELOG.txt                                             | 1 +
 docs/reference/management_commands.rst                    | 8 ++++++++
 docs/releases/2.5.rst                                     | 1 +
 docs/topics/search/indexing.rst                           | 4 ++++
 .../search/management/commands/wagtail_update_index.py    | 4 ++++
 5 files changed, 18 insertions(+)
 create mode 100644 wagtail/search/management/commands/wagtail_update_index.py

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index cd3f386b63..3d3f1cafd4 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -12,6 +12,7 @@ Changelog
  * Preserve links when copy-pasting rich text content from Wagtail to other tools (Thibaud Colas)
  * Rich text to contentstate conversion now prioritises more specific rules, to accommodate `<p>` and `<br>` elements with attributes (Matt Westcott)
  * Added limit image upload size by number of pixels (Thomas Elliott)
+ * Added `manage.py wagtail_update_index` alias to avoid clashes with `update_index` commands from other packages (Matt Westcott)
  * Fix: Set `SERVER_PORT` to 443 in `Page.dummy_request()` for HTTPS sites (Sergey Fedoseev)
  * Fix: Include port number in `Host` header of `Page.dummy_request()` (Sergey Fedoseev)
  * Fix: Validation error messages in `InlinePanel` no longer count towards `max_num` when disabling the 'add' button (Todd Dembrey, Thibaud Colas)
diff --git a/docs/reference/management_commands.rst b/docs/reference/management_commands.rst
index 8a897d3e82..3b9e212501 100644
--- a/docs/reference/management_commands.rst
+++ b/docs/reference/management_commands.rst
@@ -93,6 +93,14 @@ You can prevent the ``update_index`` command from indexing any data by using the
     $ python manage.py update_index --schema-only
 
 
+.. _wagtail_update_index:
+
+wagtail_update_index
+--------------------
+
+An alias for the ``update_index`` command that can be used when another installed package (such as `Haystack <http://haystacksearch.org/>`_) provides a command named ``update_index``. In this case, the other package's entry in ``INSTALLED_APPS`` should appear above ``wagtail.search`` so that its ``update_index`` command takes precedence over Wagtail's.
+
+
 .. _search_garbage_collect:
 
 search_garbage_collect
diff --git a/docs/releases/2.5.rst b/docs/releases/2.5.rst
index 94988b3b56..1ceb1f4321 100644
--- a/docs/releases/2.5.rst
+++ b/docs/releases/2.5.rst
@@ -22,6 +22,7 @@ Other features
  * Preserve links when copy-pasting rich text content from Wagtail to other tools (Thibaud Colas)
  * Rich text to contentstate conversion now prioritises more specific rules, to accommodate ``<p>`` and ``<br>`` elements with attributes (Matt Westcott)
  * Added limit image upload size by number of pixels (Thomas Elliott)
+ * Added ``manage.py wagtail_update_index`` alias to avoid clashes with ``update_index`` commands from other packages (Matt Westcott)
 
 
 Bug fixes
diff --git a/docs/topics/search/indexing.rst b/docs/topics/search/indexing.rst
index ba136f094f..ad787dde12 100644
--- a/docs/topics/search/indexing.rst
+++ b/docs/topics/search/indexing.rst
@@ -56,6 +56,10 @@ It is recommended to run this command once a week and at the following times:
 
 The search may not return any results while this command is running, so avoid running it at peak times.
 
+.. note::
+
+    The ``update_index`` command is also aliased as ``wagtail_update_index``, for use when another installed package (such as `Haystack <http://haystacksearch.org/>`_) provides a conflicting ``update_index`` command. In this case, the other package's entry in ``INSTALLED_APPS`` should appear above ``wagtail.search`` so that its ``update_index`` command takes precedence over Wagtail's.
+
 
 .. _wagtailsearch_indexing_fields:
 
diff --git a/wagtail/search/management/commands/wagtail_update_index.py b/wagtail/search/management/commands/wagtail_update_index.py
new file mode 100644
index 0000000000..7e9ad2a67f
--- /dev/null
+++ b/wagtail/search/management/commands/wagtail_update_index.py
@@ -0,0 +1,4 @@
+# Alias for the update_index command, to avoid clashes with other packages
+# that implement an update_index command (such as django-haystack)
+
+from wagtail.search.management.commands.update_index import Command  # NOQA