Last active
August 29, 2015 14:05
-
-
Save adamfranco/39394f34b4f6be8440cc to your computer and use it in GitHub Desktop.
remove_user_pages.php (Drupal 7)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is a drush-script for removing the user-pages created by default by | |
* Monster Menus. It just needs to be run once from the command line to get | |
* rid of all of the existing pages and make the settings-change to avoid | |
* the creation of new pages. | |
* | |
* drush --user=1 php-script remove_user_pages.php | |
* | |
*/ | |
echo "\nRemoving user-pages on '".variable_get('site_name')."'...\n\n"; | |
// Set Monster Menus to stop creating user pages. | |
variable_set('mm_use_user_dir', FALSE); | |
// Find all of the user pages and delete them. | |
$users_mmtid = mm_content_users_mmtid(); | |
echo "\$users_mmtid=$users_mmtid\n"; | |
// There are too many user pages to fetch at a single time with mm_content_get_tree(), so | |
// we'll query potential children and loop through them one by one. | |
$r = db_query('SELECT mmtid, name FROM mm_tree WHERE parent = :parent AND NOT name LIKE (\'.%\')', array(':parent' => $users_mmtid)); | |
$user_pages = $r->fetchAll(); | |
echo "Found ".count($user_pages)." pages under the users mmtid.\n"; | |
$per_marker = round(count($user_pages) / 100); | |
$i = 0; | |
print "\nDeleting users pages:\n"; | |
print "|".str_repeat('-', 98)."|\n"; | |
foreach ($user_pages as $user_page) { | |
$result = mm_content_delete($user_page->mmtid); | |
if ($result) { | |
die($result); | |
} | |
$i++; | |
if ($i % $per_marker == 0) { | |
print '.'; | |
} | |
} | |
print "\nDelete complete.\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment