summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/maintenance/removeDuplicateEntities.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/maintenance/removeDuplicateEntities.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/maintenance/removeDuplicateEntities.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/maintenance/removeDuplicateEntities.php b/www/wiki/extensions/SemanticMediaWiki/maintenance/removeDuplicateEntities.php
new file mode 100644
index 00000000..a058f167
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/maintenance/removeDuplicateEntities.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace SMW\Maintenance;
+
+use SMW\ApplicationFactory;
+use SMW\Setup;
+
+$basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv(
+'MW_INSTALL_PATH' ) : __DIR__ . '/../../..';
+
+require_once $basePath . '/maintenance/Maintenance.php';
+
+/**
+ * @license GNU GPL v2+
+ * @since 3.0
+ *
+ * @author mwjames
+ */
+class RemoveDuplicateEntities extends \Maintenance {
+
+ /**
+ * @since 3.0
+ */
+ public function __construct() {
+ $this->mDescription = 'Remove duplicate entities without active references.';
+ $this->addOption( 's', 'ID starting point', false, true );
+
+ parent::__construct();
+ }
+
+ /**
+ * @see Maintenance::addDefaultParams
+ *
+ * @since 3.0
+ */
+ protected function addDefaultParams() {
+ parent::addDefaultParams();
+ }
+
+ /**
+ * @see Maintenance::execute
+ */
+ public function execute() {
+
+ if ( !Setup::isEnabled() ) {
+ $this->reportMessage( "\nYou need to have SMW enabled in order to run the maintenance script!\n" );
+ exit;
+ }
+
+ if ( !Setup::isValid() ) {
+ $this->reportMessage( "\nYou need to run `update.php` or `setupStore.php` first before continuing\nwith any maintenance tasks!\n" );
+ exit;
+ }
+
+ $this->reportMessage(
+ "\nThe script will only dispose of those duplicate entities that have no active\n" .
+ "references. The log section 'untouched' contains IDs that have not been\n" .
+ "removed and the user is asked to verify the content and manually remove\n".
+ "those listed entities.\n\n"
+ );
+
+ $applicationFactory = ApplicationFactory::getInstance();
+ $maintenanceFactory = $applicationFactory->newMaintenanceFactory();
+
+ $duplicateEntitiesDisposer = $maintenanceFactory->newDuplicateEntitiesDisposer(
+ $applicationFactory->getStore( 'SMW\SQLStore\SQLStore' ),
+ [ $this, 'reportMessage' ]
+ );
+
+ $duplicateEntityRecords = $duplicateEntitiesDisposer->findDuplicates();
+ $duplicateEntitiesDisposer->verifyAndDispose( $duplicateEntityRecords );
+
+ return true;
+ }
+
+ /**
+ * @see Maintenance::reportMessage
+ *
+ * @since 1.9
+ *
+ * @param string $message
+ */
+ public function reportMessage( $message ) {
+ $this->output( $message );
+ }
+
+}
+
+$maintClass = 'SMW\Maintenance\RemoveDuplicateEntities';
+require_once( RUN_MAINTENANCE_IF_MAIN );