Exemplo n.º 1
0
/**
 * Create a standard object from a given entity row.
 *
 * @param stdClass $row The row of the entry in the entities table.
 *
 * @return ElggEntity|false
 * @link http://docs.elgg.org/DataModel/Entities
 * @see get_entity_as_row()
 * @see add_subtype()
 * @see get_entity()
 * @access private
 *
 * @throws ClassException|InstallationException
 */
function elasticsearch_entity_row_to_std($row)
{
    if (!$row instanceof stdClass) {
        return $row;
    }
    if (!isset($row->guid) || !isset($row->subtype)) {
        return $row;
    }
    $new_entity = false;
    // Create a memcache cache if we can
    static $newentity_cache;
    if (!$newentity_cache && is_memcache_available()) {
        $newentity_cache = new ElggMemcache('new_entity_cache');
    }
    if ($newentity_cache) {
        $new_entity = $newentity_cache->load($row->guid);
    }
    if ($new_entity) {
        return $new_entity;
    }
    try {
        // load class for entity if one is registered
        $classname = get_subtype_class_from_id($row->subtype);
        if ($classname != "") {
            if (class_exists($classname)) {
                $new_entity = new $classname($row);
                if (!$new_entity instanceof ElggEntity) {
                    $msg = elgg_echo('ClassException:ClassnameNotClass', array($classname, 'ElggEntity'));
                    throw new ClassException($msg);
                }
            }
        }
        if (!$new_entity) {
            switch ($row->type) {
                case 'object':
                    $new_entity = new ElggObject($row);
                    break;
                case 'user':
                    $new_entity = new ElggUser($row);
                    break;
                case 'group':
                    $new_entity = new ElggGroup($row);
                    break;
                case 'site':
                    $new_entity = new ElggSite($row);
                    break;
                default:
                    $msg = elgg_echo('InstallationException:TypeNotSupported', array($row->type));
                    throw new InstallationException($msg);
            }
        }
    } catch (IncompleteEntityException $e) {
        return false;
    }
    return $new_entity;
}
Exemplo n.º 2
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
 */
function wizard_upgrade_system_handler($event, $type, $object)
{
    $id = get_subtype_id('object', Wizard::SUBTYPE);
    if (empty($id)) {
        // add subtype registration
        add_subtype('object', Wizard::SUBTYPE, 'Wizard');
    } elseif (get_subtype_class_from_id($id) !== 'Wizard') {
        // update subtype registration
        update_subtype('object', Wizard::SUBTYPE, 'Wizard');
    }
}
Exemplo n.º 3
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 fixClasses($event, $type, $object)
 {
     $id = get_subtype_id('object', \Wizard::SUBTYPE);
     if (empty($id)) {
         // add subtype registration
         add_subtype('object', \Wizard::SUBTYPE, 'Wizard');
     } elseif (get_subtype_class_from_id($id) !== 'Wizard') {
         // update subtype registration
         update_subtype('object', \Wizard::SUBTYPE, 'Wizard');
     }
     $id = get_subtype_id('object', \WizardStep::SUBTYPE);
     if (empty($id)) {
         // add subtype registration
         add_subtype('object', \WizardStep::SUBTYPE, 'WizardStep');
     } elseif (get_subtype_class_from_id($id) !== 'WizardStep') {
         // update subtype registration
         update_subtype('object', \WizardStep::SUBTYPE, 'WizardStep');
     }
 }
Exemplo n.º 4
0
/**
 * Create an Elgg* object from a given entity row.
 *
 * Handles loading all tables into the correct class.
 *
 * @param stdClass $row The row of the entry in the entities table.
 *
 * @return object|false
 * @link http://docs.elgg.org/DataModel/Entities
 * @see get_entity_as_row()
 * @see add_subtype()
 * @see get_entity()
 * @access private
 */
function entity_row_to_elggstar($row)
{
    if (!$row instanceof stdClass) {
        return $row;
    }
    if (!isset($row->guid) || !isset($row->subtype)) {
        return $row;
    }
    $new_entity = false;
    // Create a memcache cache if we can
    static $newentity_cache;
    if (!$newentity_cache && is_memcache_available()) {
        $newentity_cache = new ElggMemcache('new_entity_cache');
    }
    if ($newentity_cache) {
        $new_entity = $newentity_cache->load($row->guid);
    }
    if ($new_entity) {
        return $new_entity;
    }
    // load class for entity if one is registered
    $classname = get_subtype_class_from_id($row->subtype);
    if ($classname != "") {
        if (class_exists($classname)) {
            $new_entity = new $classname($row);
            if (!$new_entity instanceof ElggEntity) {
                $msg = elgg_echo('ClassException:ClassnameNotClass', array($classname, 'ElggEntity'));
                throw new ClassException($msg);
            }
        } else {
            error_log(elgg_echo('ClassNotFoundException:MissingClass', array($classname)));
        }
    }
    if (!$new_entity) {
        //@todo Make this into a function
        switch ($row->type) {
            case 'object':
                $new_entity = new ElggObject($row);
                break;
            case 'user':
                $new_entity = new ElggUser($row);
                break;
            case 'group':
                $new_entity = new ElggGroup($row);
                break;
            case 'site':
                $new_entity = new ElggSite($row);
                break;
            default:
                $msg = elgg_echo('InstallationException:TypeNotSupported', array($row->type));
                throw new InstallationException($msg);
        }
    }
    // Cache entity if we have a cache available
    if ($newentity_cache && $new_entity) {
        $newentity_cache->save($new_entity->guid, $new_entity);
    }
    return $new_entity;
}
Exemplo n.º 5
0
 /**
  * Create an Elgg* object from a given entity row.
  *
  * Handles loading all tables into the correct class.
  *
  * @param \stdClass $row The row of the entry in the entities table.
  *
  * @return \ElggEntity|false
  * @see get_entity_as_row()
  * @see add_subtype()
  * @see get_entity()
  * @access private
  *
  * @throws \ClassException|\InstallationException
  */
 function rowToElggStar($row)
 {
     if (!$row instanceof \stdClass) {
         return $row;
     }
     if (!isset($row->guid) || !isset($row->subtype)) {
         return $row;
     }
     $new_entity = false;
     // Create a memcache cache if we can
     static $newentity_cache;
     if (!$newentity_cache && is_memcache_available()) {
         $newentity_cache = new \ElggMemcache('new_entity_cache');
     }
     if ($newentity_cache) {
         $new_entity = $newentity_cache->load($row->guid);
     }
     if ($new_entity) {
         return $new_entity;
     }
     // load class for entity if one is registered
     $classname = get_subtype_class_from_id($row->subtype);
     if ($classname != "") {
         if (class_exists($classname)) {
             $new_entity = new $classname($row);
             if (!$new_entity instanceof \ElggEntity) {
                 $msg = $classname . " is not a " . '\\ElggEntity' . ".";
                 throw new \ClassException($msg);
             }
         } else {
             error_log("Class '" . $classname . "' was not found, missing plugin?");
         }
     }
     if (!$new_entity) {
         //@todo Make this into a function
         switch ($row->type) {
             case 'object':
                 $new_entity = new \ElggObject($row);
                 break;
             case 'user':
                 $new_entity = new \ElggUser($row);
                 break;
             case 'group':
                 $new_entity = new \ElggGroup($row);
                 break;
             case 'site':
                 $new_entity = new \ElggSite($row);
                 break;
             default:
                 $msg = "Entity type " . $row->type . " is not supported.";
                 throw new \InstallationException($msg);
         }
     }
     // Cache entity if we have a cache available
     if ($newentity_cache && $new_entity) {
         $newentity_cache->save($new_entity->guid, $new_entity);
     }
     return $new_entity;
 }
<?php

set_time_limit(0);
$i = 0;
$dbprefix = elgg_get_config('dbprefix');
$groups = get_input('groups');
foreach ($groups as $guid => $subtype) {
    if (!$subtype) {
        continue;
    }
    $target_subtype_id = get_subtype_id('group', $subtype);
    if (!$target_subtype_id) {
        continue;
    }
    // Update entities table
    $query = "UPDATE {$dbprefix}entities SET subtype={$target_subtype_id} WHERE guid={$guid}";
    update_data($query);
    // Update river table
    $query = "UPDATE {$dbprefix}river SET subtype='{$subtype}' WHERE object_guid={$guid}";
    update_data($query);
    // Update system log table
    $target_class = get_subtype_class_from_id($target_subtype_id) ?: 'ElggGroup';
    $query = "UPDATE {$dbprefix}system_log SET object_subtype='{$subtype}', object_class='{$target_class}' WHERE object_id='{$guid}'";
    update_data($query);
    $i++;
}
system_message(elgg_echo('admin:groups:subtypes:change_subtype:success', array($i)));