public function testCanFindUpgradesByFullUrl()
 {
     $this->obj->_callable_egefps = array($this, 'mock_egefps_for_full_url');
     $this->obj->upgrade_url = elgg_normalize_url('test');
     $upgrade = $this->obj->getUpgradeFromPath('test');
     $this->assertTrue((bool) $upgrade);
     $this->assertSame('test', $upgrade->upgrade_url);
 }
Exemple #2
0
 public static function convertTimestamps($event, $type, $object)
 {
     $ia = elgg_set_ignore_access(true);
     $path = 'admin/upgrades/convert_timestamps';
     $upgrade = new \ElggUpgrade();
     if (!$upgrade->getUpgradeFromPath($path)) {
         $upgrade->setPath($path);
         $upgrade->title = elgg_echo('admin:upgrades:convert_timestamps');
         $upgrade->description = elgg_echo('admin:upgrades:convert_timestamps:description');
         $upgrade->save();
     }
     elgg_set_ignore_access($ia);
 }
Exemple #3
0
 /**
  * Listen to the upgrade event to check if there is any old content with unsent tag notifications
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $entity supplied entity/params
  *
  * @return void
  */
 public static function markOldTagsAsSent($event, $type, $entity)
 {
     $path = 'admin/upgrades/set_tag_notifications_sent';
     $upgrade = new \ElggUpgrade();
     // ignore acces while checking for existence
     $ia = elgg_set_ignore_access(true);
     // already registered?
     if (!$upgrade->getUpgradeFromPath($path)) {
         $upgrade->title = elgg_echo('admin:upgrades:set_tag_notifications_sent');
         $upgrade->description = elgg_echo('admin:upgrades:set_tag_notifications_sent:description');
         $upgrade->setPath($path);
         $upgrade->save();
     }
     // restore access
     elgg_set_ignore_access($ia);
 }
Exemple #4
0
 /**
  * Register an upgrade class to move the blog icons
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $object supplied object/params
  *
  * @return void
  */
 public static function moveBlogIcons($event, $type, $object)
 {
     $ia = elgg_set_ignore_access(true);
     $path = 'admin/upgrades/blog_tools_move_icons';
     $upgrade = new \ElggUpgrade();
     if (!$upgrade->getUpgradeFromPath($path)) {
         $upgrade->setPath($path);
         $upgrade->title = elgg_echo('admin:upgrades:blog_tools_move_icons');
         $upgrade->description = elgg_echo('admin:upgrades:blog_tools_move_icons:description');
         $upgrade->save();
         // check for blog with icons
         // eg. if non found, no upgrade needed
         $count = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => 'blog', 'metadata_name' => 'icontime', 'count' => true]);
         if (empty($count)) {
             $upgrade->setCompleted();
         }
     }
     // restore access
     elgg_set_ignore_access($ia);
 }
Exemple #5
0
/**
 * Listen to the upgrade event to make sure upgrades can be run
 *
 * @param string $event  the name of the event
 * @param string $type   the type of the event
 * @param null   $object nothing
 *
 * @return void
 */
function thewire_tools_upgrade_system_event_handler($event, $type, $object)
{
    // Upgrade also possible hidden entities. This feature get run
    // by an administrator so there's no need to ignore access.
    $access_status = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    // register an upgrade script
    $options = array("type" => "user", "plugin_id" => "thewire_tools", "plugin_user_setting_name" => "notify_mention", "count" => true);
    $count = elgg_get_entities_from_plugin_user_settings($options);
    if ($count) {
        $path = "admin/upgrades/thewire_tools_mentions";
        $upgrade = new ElggUpgrade();
        if (!$upgrade->getUpgradeFromPath($path)) {
            $upgrade->setPath($path);
            $upgrade->title = "TheWire Tools mentions upgrade";
            $upgrade->description = "The way mention notifications are handled has changed. Run this script to make sure all settings are migrated.";
            $upgrade->save();
        }
    }
    access_show_hidden_entities($access_status);
}
Exemple #6
0
/**
 * Listen to the upgrade event
 *
 * @param string $event  name of the event
 * @param string $type   type of the event
 * @param null   $object supplied object
 *
 * @return void
 */
function content_subscriptions_upgrade_system_handler($event, $type, $object)
{
    // Upgrade also possible hidden entities. This feature get run
    // by an administrator so there's no need to ignore access.
    $access_status = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    // register an upgrade script
    $options = array("type" => "user", "relationship" => CONTENT_SUBSCRIPTIONS_SUBSCRIPTION, "inverse_relationship" => true, "count" => true);
    $count = elgg_get_entities_from_relationship($options);
    if ($count) {
        $path = "admin/upgrades/content_subscriptions";
        $upgrade = new ElggUpgrade();
        if (!$upgrade->getUpgradeFromPath($path)) {
            $upgrade->setPath($path);
            $upgrade->title = "Content Subscription upgrade";
            $upgrade->description = "The way content subscriptions are handled has changed. Run this script to make sure all content subscriptions are migrated.";
            $upgrade->save();
        }
    }
    access_show_hidden_entities($access_status);
}
Exemple #7
0
    /**
     * Listen to the upgrade event, to register a script
     *
     * @param string $event  name of the event
     * @param string $type   type of the event
     * @param null   $object supplied object
     *
     * @return void
     */
    public static function registerScript($event, $type, $object)
    {
        // Upgrade also possible hidden entities. This feature get run
        // by an administrator so there's no need to ignore access.
        $access_status = access_get_show_hidden_status();
        access_show_hidden_entities(true);
        // register an upgrade script
        $options = array('type' => 'user', 'relationship' => CONTENT_SUBSCRIPTIONS_SUBSCRIPTION, 'inverse_relationship' => true, 'count' => true);
        $count = elgg_get_entities_from_relationship($options);
        if ($count) {
            $path = 'admin/upgrades/content_subscriptions';
            $upgrade = new \ElggUpgrade();
            if (!$upgrade->getUpgradeFromPath($path)) {
                $upgrade->setPath($path);
                $upgrade->title = 'Content Subscription upgrade';
                $upgrade->description = 'The way content subscriptions are handled has changed.
					Run this script to make sure all content subscriptions are migrated.';
                $upgrade->save();
            }
        }
        access_show_hidden_entities($access_status);
    }
Exemple #8
0
 /**
  * Listen to upgrade event
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $object supplied params
  *
  * @return void
  */
 public static function migrateSteps($event, $type, $object)
 {
     $path = 'admin/upgrades/migrate_wizard_steps';
     $upgrade = new \ElggUpgrade();
     // ignore acces while checking for existence
     $ia = elgg_set_ignore_access(true);
     // already registered?
     if ($upgrade->getUpgradeFromPath($path)) {
         // restore access
         elgg_set_ignore_access($ia);
         return;
     }
     // find if upgrade is needed
     $upgrade_needed = false;
     $batch = new \ElggBatch('elgg_get_entities', ['type' => 'object', 'subtype' => \Wizard::SUBTYPE, 'limit' => false]);
     foreach ($batch as $entity) {
         $fa = new \ElggFile();
         $fa->owner_guid = $entity->getGUID();
         $fa->setFilename('steps.json');
         if (!$fa->exists()) {
             continue;
         }
         $upgrade_needed = true;
         break;
     }
     if (!$upgrade_needed) {
         // restore access
         elgg_set_ignore_access($ia);
         return;
     }
     $upgrade->title = elgg_echo('admin:upgrades:migrate_wizard_steps');
     $upgrade->description = elgg_echo('admin:upgrades:migrate_wizard_steps:description');
     $upgrade->setPath($path);
     $upgrade->save();
     // restore access
     elgg_set_ignore_access($ia);
 }
<?php

/**
 * Convert comment annotations to entities
 *
 * Run for 2 seconds per request as set by $batch_run_time_in_secs. This includes
 * the engine loading time.
 */
// from engine/start.php
global $START_MICROTIME;
$batch_run_time_in_secs = 2;
// if upgrade has run correctly, mark it done
if (get_input('upgrade_completed')) {
    // set the upgrade as completed
    $factory = new ElggUpgrade();
    $upgrade = $factory->getUpgradeFromPath('admin/upgrades/comments');
    if ($upgrade instanceof ElggUpgrade) {
        $upgrade->setCompleted();
    }
    return true;
}
// Offset is the total amount of errors so far. We skip these
// comments to prevent them from possibly repeating the same error.
$offset = get_input('offset', 0);
$limit = 50;
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
// don't want any event or plugin hook handlers from plugins to run
$original_events = _elgg_services()->events;
$original_hooks = _elgg_services()->hooks;
_elgg_services()->events = new Elgg_EventsService();
<?php

/**
 * Migrate containers of static pages
 */
$success_count = 0;
$error_count = 0;
if (get_input('upgrade_completed')) {
    // set the upgrade as completed
    $factory = new \ElggUpgrade();
    $upgrade = $factory->getUpgradeFromPath('admin/upgrades/static/migrate_containers');
    if ($upgrade instanceof \ElggUpgrade) {
        $upgrade->setCompleted();
    }
    return true;
}
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$dbprefix = elgg_get_config('dbprefix');
$name_id = elgg_get_metastring_id('parent_guid');
$batch = new \ElggBatch('elgg_get_entities', ['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'wheres' => ["e.guid NOT IN (SELECT entity_guid FROM {$dbprefix}metadata WHERE name_id = {$name_id})"]]);
$batch->setIncrementOffset(false);
foreach ($batch as $page) {
    $success_count++;
    if ($page->parent_guid) {
        // already converted
        continue;
    }
    $root = $page->getRootPage();
    if ($root instanceof \StaticPage) {
        $page->parent_guid = $page->container_guid;
Exemple #11
0
 /**
  * Migrates static pages to be using 'normal' containers and move parent relationship to parent_guid metadata
  * The previous migration using static pages as containers backfired in places like search, (write) access, listings
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $entity supplied entity
  *
  * @return void
  * @since 5.0
  */
 public static function migrateContainers($event, $type, $object)
 {
     $ia = elgg_set_ignore_access(true);
     $path = 'admin/upgrades/static/migrate_containers';
     $upgrade = new \ElggUpgrade();
     if (!$upgrade->getUpgradeFromPath($path)) {
         $upgrade->setPath($path);
         $upgrade->title = elgg_echo('admin:upgrades:static:migrate_containers');
         $upgrade->description = elgg_echo('admin:upgrades:static:migrate_containers:description');
         $upgrade->save();
     }
     elgg_set_ignore_access($ia);
 }
            foreach ($files as $file) {
                $file_name = $file['file'];
                $old_file->setFilename("events/{$event->guid}/files/{$file_name}");
                if ($old_file->exists()) {
                    $new_file->setFilename("files/{$file_name}");
                    $new_file->open('write');
                    if ($new_file->write($old_file->grabFile())) {
                        $old_file->delete();
                    }
                    $new_file->close();
                }
            }
        }
    }
    $offset++;
    $session->set('event_manager_files_migration_offset', $offset);
    $success_count++;
}
access_show_hidden_entities($access_status);
if ($start_offset === $offset) {
    // no new entities found to process
    // set the upgrade as completed
    $factory = new \ElggUpgrade();
    $upgrade = $factory->getUpgradeFromPath('admin/upgrades/migrate_files_to_event');
    if ($upgrade instanceof \ElggUpgrade) {
        $upgrade->setCompleted();
    }
    return true;
}
// Give some feedback for the UI
echo json_encode(['numSuccess' => $success_count, 'numErrors' => 0]);
<?php

/**
 * Data dirs upgrade page
 */
// Upgrade also possible hidden users. This feature get run
// by an administrator so there's no need to ignore access.
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$factory = new ElggUpgrade();
$upgrade = $factory->getUpgradeFromPath('admin/upgrades/datadirs');
if ($upgrade->isCompleted()) {
    $count = 0;
} else {
    $helper = new Elgg_Upgrades_Helper2013022000(elgg_get_site_entity()->guid, elgg_get_config('dbprefix'));
    $helper->forgetFailures();
    $count = $helper->countUnmigratedUsers();
}
echo elgg_view('admin/upgrades/view', array('count' => $count, 'action' => 'action/admin/upgrades/upgrade_datadirs'));
access_show_hidden_entities($access_status);
<?php

// Upgrade also possible hidden entities. This feature get run
// by an administrator so there's no need to ignore access.
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$count = 0;
// make sure no left over from previous run
$session = elgg_get_session();
$session->remove('blog_tools_move_icon_offset');
// check if upgrade is done
$path = 'admin/upgrades/blog_tools_move_icons';
$factory = new \ElggUpgrade();
$upgrade = $factory->getUpgradeFromPath($path);
if (empty($upgrade) || !$upgrade->isCompleted()) {
    // get the count off the items to move
    $count = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => 'blog', 'metadata_name' => 'icontime', 'count' => true]);
}
echo elgg_view('output/longtext', ['value' => elgg_echo('admin:upgrades:blog_tools_move_icons:description')]);
echo elgg_view('admin/upgrades/view', ['count' => $count, 'action' => 'action/blog_tools/upgrades/move_icons']);
access_show_hidden_entities($access_status);
Exemple #15
0
$original_events = _elgg_services()->events;
$original_hooks = _elgg_services()->hooks;
_elgg_services()->events = new Elgg_EventsService();
_elgg_services()->hooks = new Elgg_PluginHooksService();
elgg_register_plugin_hook_handler("permissions_check", "all", "elgg_override_permissions");
elgg_register_plugin_hook_handler("container_permissions_check", "all", "elgg_override_permissions");
_elgg_services()->db->disableQueryCache();
$success_count = 0;
$error_count = 0;
while (microtime(true) - $START_MICROTIME < $batch_run_time_in_secs) {
    $options = array("type" => "user", "plugin_id" => "thewire_tools", "plugin_user_setting_name" => "notify_mention", "count" => true);
    $count = elgg_get_entities_from_plugin_user_settings($options);
    if (!$count) {
        // no old subscriptions left
        $factory = new ElggUpgrade();
        $upgrade = $factory->getUpgradeFromPath("admin/upgrades/thewire_tools_mentions");
        if ($upgrade instanceof ElggUpgrade) {
            $upgrade->setCompleted();
        }
        break;
    }
    $options["count"] = false;
    $options["offset"] = $offset;
    $options["limit"] = $limit;
    $users = elgg_get_entities_from_plugin_user_settings($options);
    foreach ($users as $user) {
        $setting = elgg_get_plugin_user_setting("notify_mention", $user->getGUID(), "thewire_tools");
        if ($setting == "yes") {
            $notification_settings = get_user_notification_settings($user->getGUID());
            if (!empty($notification_settings)) {
                $notification_settings = (array) $notification_settings;
Exemple #16
0
$original_events = _elgg_services()->events;
$original_hooks = _elgg_services()->hooks;
_elgg_services()->events = new Elgg_EventsService();
_elgg_services()->hooks = new Elgg_PluginHooksService();
elgg_register_plugin_hook_handler("permissions_check", "all", "elgg_override_permissions");
elgg_register_plugin_hook_handler("container_permissions_check", "all", "elgg_override_permissions");
_elgg_services()->db->disableQueryCache();
$success_count = 0;
$error_count = 0;
while (microtime(true) - $START_MICROTIME < $batch_run_time_in_secs) {
    $options = array("type" => "user", "relationship" => CONTENT_SUBSCRIPTIONS_SUBSCRIPTION, "inverse_relationship" => true, "count" => true);
    $count = elgg_get_entities_from_relationship($options);
    if (!$count) {
        // no old subscriptions left
        $factory = new ElggUpgrade();
        $upgrade = $factory->getUpgradeFromPath("admin/upgrades/content_subscriptions");
        if ($upgrade instanceof ElggUpgrade) {
            $upgrade->setCompleted();
        }
        break;
    }
    $options["count"] = false;
    $options["offset"] = $offset;
    $options["limit"] = $limit;
    $users = elgg_get_entities_from_relationship($options);
    foreach ($users as $user) {
        $error_counter = 0;
        $subscription_options = array("relationship" => CONTENT_SUBSCRIPTIONS_SUBSCRIPTION, "relationship_guid" => $user->getGUID(), "limit" => false);
        $batch = new ElggBatch("elgg_get_entities_from_relationship", $subscription_options);
        $batch->setIncrementOffset(false);
        foreach ($batch as $entity) {
 * in actions/admin/upgrades/upgrade_discussion_replies.php for that.
 *
 * This upgrade must be run even if the groups plugin is disabled because the
 * script will be removed in Elgg 1.10 and we don't want anyone to get stuck
 * with old annotation replies just because the groups plugin was not enabled
 * when site was upgraded from 1.8.
 */
// Register subtype and class for discussion replies
if (get_subtype_id('object', 'discussion_reply')) {
    update_subtype('object', 'discussion_reply', 'ElggDiscussionReply');
} else {
    add_subtype('object', 'discussion_reply', 'ElggDiscussionReply');
}
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$ia = elgg_set_ignore_access(true);
$discussion_replies = elgg_get_annotations(array('annotation_names' => 'group_topic_post', 'count' => true));
// Notify administrator only if there are existing discussion replies
if ($discussion_replies) {
    $path = "admin/upgrades/discussion_replies";
    $upgrade = new \ElggUpgrade();
    // Create the upgrade if one with the same URL doesn't already exist
    if (!$upgrade->getUpgradeFromPath($path)) {
        $upgrade->setPath($path);
        $upgrade->title = 'Group Discussions Upgrade';
        $upgrade->description = 'Group discussions have been improved in Elgg 1.9 and require a migration. Run this upgrade to complete the migration.';
        $upgrade->save();
    }
}
elgg_set_ignore_access($ia);
access_show_hidden_entities($access_status);
<?php

/**
 * Migrate timestamp of events
 */
$success_count = 0;
$error_count = 0;
if (get_input('upgrade_completed')) {
    // set the upgrade as completed
    $factory = new \ElggUpgrade();
    $upgrade = $factory->getUpgradeFromPath('admin/upgrades/convert_timestamps');
    if ($upgrade instanceof \ElggUpgrade) {
        $upgrade->setCompleted();
    }
    return true;
}
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$batch = new \ElggBatch('elgg_get_entities_from_metadata', ['type' => 'object', 'subtype' => \Event::SUBTYPE, 'limit' => 25, 'metadata_names' => ['start_day']]);
$batch->setIncrementOffset(false);
foreach ($batch as $event) {
    $success_count++;
    if ($event->event_start) {
        // already converted
        continue;
    }
    $event_start = gmmktime(0, 0, 0, date('m', $event->start_day), date('d', $event->start_day), date('Y', $event->start_day));
    if ($event->start_time) {
        $hours = date('H', $event->start_time);
        $minutes = date('i', $event->start_time);
        $event_start += $minutes * 60;
<?php

/**
 * Convert discussion replies from annotations to entities
 *
 * Run for 2 seconds per request as set by $batch_run_time_in_secs. This includes
 * the engine loading time.
 */
// from engine/start.php
global $START_MICROTIME;
$batch_run_time_in_secs = 2;
if (get_input('upgrade_completed')) {
    // set the upgrade as completed
    $factory = new ElggUpgrade();
    $upgrade = $factory->getUpgradeFromPath('admin/upgrades/discussion_replies');
    if ($upgrade instanceof ElggUpgrade) {
        $upgrade->setCompleted();
    }
    return true;
}
// Offset is the total amount of errors so far. We skip these
// annotations to prevent them from possibly repeating the same error.
$offset = get_input('offset', 0);
$limit = 50;
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
// don't want any event or plugin hook handlers from plugins to run
$original_events = _elgg_services()->events;
$original_hooks = _elgg_services()->hooks;
_elgg_services()->events = new Elgg\EventsService();
_elgg_services()->hooks = new Elgg\PluginHooksService();
<?php

use Elgg\EntityDirLocator;
use hypeJunction\Scraper\ScraperService;
if (get_input('upgrade_completed')) {
    $factory = new ElggUpgrade();
    $upgrade = $factory->getUpgradeFromPath('admin/upgrades/scraper/move_to_db');
    if ($upgrade instanceof ElggUpgrade) {
        $upgrade->setCompleted();
    }
    return true;
}
$svc = ScraperService::getInstance();
$site = elgg_get_site_entity();
$dataroot = elgg_get_config('dataroot');
$dir = new EntityDirLocator($site->guid);
$paths = elgg_get_file_list($dataroot . $dir . 'scraper_cache/resources/');
$original_time = microtime(true);
$time_limit = 4;
$success_count = 0;
$error_count = 0;
$response = [];
while (count($paths) > 0 && microtime(true) - $original_time < $time_limit) {
    $path = array_shift($paths);
    error_log((string) count($paths));
    $response['upgraded'][] = $path;
    $success_count++;
    $basename = pathinfo($path, PATHINFO_BASENAME);
    $file = new ElggFile();
    $file->owner_guid = $site->guid;
    $file->setFilename("scraper_cache/resources/{$basename}");