Example #1
0
<?php

/**
 * Update the notifications based on all friends and access collections
 */
// loop through all users checking collections and notifications
global $ENTITY_CACHE, $CONFIG;
global $NOTIFICATION_HANDLERS;
$users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity\n\tWHERE username != ''");
while ($user = mysql_fetch_object($users)) {
    $ENTITY_CACHE = array();
    _elgg_invalidate_query_cache();
    $user = get_entity($user->guid);
    foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
        $notify = "notify{$method}";
        $metaname = "collections_notifications_preferences_{$method}";
        $collections_preferences = $user->{$metaname};
        if (!$collections_preferences) {
            continue;
        }
        if (!is_array($collections_preferences)) {
            $collections_preferences = array($collections_preferences);
        }
        foreach ($collections_preferences as $collection_id) {
            // check the all friends notifications
            if ($collection_id == -1) {
                $options = array('relationship' => 'friend', 'relationship_guid' => $user->guid, 'limit' => 0);
                $friends = elgg_get_entities_from_relationship($options);
                foreach ($friends as $friend) {
                    if (!check_entity_relationship($user->guid, $notify, $friend->guid)) {
                        add_entity_relationship($user->guid, $notify, $friend->guid);
Example #2
0
/**
 * Checks if upgrade is locked
 *
 * @return bool
 * @access private
 */
function _elgg_upgrade_is_locked()
{
    global $CONFIG;
    $is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}upgrade_lock'"));
    // @todo why?
    _elgg_invalidate_query_cache();
    return $is_locked;
}
Example #3
0
/**
 * Remove data from the database.
 *
 * @note Altering the DB invalidates all queries in {@link $DB_QUERY_CACHE}.
 *
 * @param string $query The SQL query to run
 *
 * @return int|false The number of affected rows or false on failure
 * @access private
 */
function delete_data($query)
{
    elgg_log("DB query {$query}", 'NOTICE');
    $dblink = get_db_link('write');
    _elgg_invalidate_query_cache();
    if (execute_query("{$query}", $dblink)) {
        return mysql_affected_rows($dblink);
    }
    return FALSE;
}
/**
 * Sent out the notifications for the provided annotation_id
 *
 * @param int    $id    the id of the annotation
 * @param string $event the type of event
 *
 * @return void
 */
function advanced_notifications_annotation_notification($id, $event)
{
    global $NOTIFICATION_HANDLERS;
    // get the annotation
    $annotation = elgg_get_annotation_from_id($id);
    if (!empty($annotation)) {
        // are notifications on this annotation allowed
        if (advanced_notifications_is_registered_notification_annotation($annotation)) {
            // get the entity the annotation was made on
            $entity = $annotation->getEntity();
            // get the owner of the annotation
            $owner = $annotation->getOwnerEntity();
            if (!empty($entity) && !empty($owner)) {
                // make sure the entity isn't a PRIVATE entity, this shouldn't happed as the commandline shouldn't be called
                if ($entity->access_id != ACCESS_PRIVATE) {
                    // is the entity a registered entity type/subtype, this shouldn't happen see above
                    $default_subject = advanced_notifications_is_registered_notification_entity($entity, true);
                    if (!empty($default_subject)) {
                        // prepare the message to sent
                        $default_message = $default_subject . ": " . $entity->getURL();
                        // check if we need to disable site notifications
                        if (elgg_get_plugin_setting("replace_site_notifications", "advanced_notifications") == "yes") {
                            unregister_notification_handler("site");
                        }
                        if (!empty($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) {
                            // this could take a long time, especialy with large groups
                            set_time_limit(0);
                            // prepare options to get the interested users
                            $options = array("type" => "user", "site_guids" => ELGG_ENTITIES_ANY_VALUE, "limit" => false, "joins" => array("JOIN " . elgg_get_config("dbprefix") . "users_entity ue ON e.guid = ue.guid"), "wheres" => array("(ue.banned = 'no')", "(e.guid <> " . $owner->getGUID() . ")"), "relationship_guid" => $entity->getContainerGUID(), "inverse_relationship" => true, "callback" => "advanced_notifications_row_to_guid");
                            foreach ($NOTIFICATION_HANDLERS as $method => $dummy) {
                                // get the interested users for the entity
                                $options["relationship"] = "notify" . $method;
                                // allow the interested user options to be ajusted
                                $params = array("annotation" => $annotation, "entity" => $entity, "options" => $options, "method" => $method);
                                $options = elgg_trigger_plugin_hook("interested_users:options", "notify:" . $method, $params, $options);
                                if (!empty($options)) {
                                    // we got through the hook, so get the users
                                    $user_guids = elgg_get_entities_from_relationship($options);
                                    if (!empty($user_guids)) {
                                        // process each user
                                        foreach ($user_guids as $user_guid) {
                                            // fetch the user entity to process
                                            $user = get_user($user_guid);
                                            if (!empty($user)) {
                                                // check if the user has access to the entity
                                                if (has_access_to_entity($entity, $user)) {
                                                    // trigger a hook to make a custom message
                                                    $message = elgg_trigger_plugin_hook("notify:annotation:message", $annotation->getSubtype(), array("annotation" => $annotation, "to_entity" => $user, "method" => $method), $default_message);
                                                    // check if the hook made a correct message
                                                    if (empty($message) && $message !== false) {
                                                        // the hook did it incorrect, so reset the message
                                                        $message = $default_message;
                                                    }
                                                    // this is new, trigger a hook to make a custom subject
                                                    $subject = elgg_trigger_plugin_hook("notify:annotation:subject", $annotation->getSubtype(), array("annotation" => $annotation, "to_entity" => $user, "method" => $method), $default_subject);
                                                    // check if the hook made a correct subject
                                                    if (empty($subject)) {
                                                        // the hook did it incorrect, so reset the subject
                                                        $subject = $default_subject;
                                                    }
                                                    // if the hook returnd false, don't sent a notification
                                                    if ($message !== false) {
                                                        notify_user($user->getGUID(), $entity->getContainerGUID(), $subject, $message, null, $method);
                                                    }
                                                }
                                            }
                                            // cleanup some of the caches
                                            _elgg_invalidate_query_cache();
                                            _elgg_invalidate_cache_for_entity($user_guid);
                                            unset($user);
                                        }
                                    }
                                    // some small cleanup
                                    unset($user_guids);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Example #5
0
 /**
  * Fetches the next chunk of results
  *
  * @return bool
  */
 private function getNextResultsChunk()
 {
     // always reset results.
     $this->results = array();
     if (!isset($this->validGetter)) {
         $this->validGetter = is_callable($this->getter);
     }
     if (!$this->validGetter) {
         return false;
     }
     $limit = $this->chunkSize;
     // if someone passed limit = 0 they want everything.
     if ($this->limit != 0) {
         if ($this->retrievedResults >= $this->limit) {
             return false;
         }
         // if original limit < chunk size, set limit to original limit
         // else if the number of results we'll fetch if greater than the original limit
         if ($this->limit < $this->chunkSize) {
             $limit = $this->limit;
         } elseif ($this->retrievedResults + $this->chunkSize > $this->limit) {
             // set the limit to the number of results remaining in the original limit
             $limit = $this->limit - $this->retrievedResults;
         }
     }
     if ($this->incrementOffset) {
         $offset = $this->offset + $this->retrievedResults;
     } else {
         $offset = $this->offset + $this->totalIncompletes;
     }
     $current_options = array('limit' => $limit, 'offset' => $offset, '__ElggBatch' => $this);
     $options = array_merge($this->options, $current_options);
     $this->incompleteEntities = array();
     $this->results = call_user_func_array($this->getter, array($options));
     // batch result sets tend to be large; we don't want to cache these.
     _elgg_invalidate_query_cache();
     $num_results = count($this->results);
     $num_incomplete = count($this->incompleteEntities);
     $this->totalIncompletes += $num_incomplete;
     if ($this->incompleteEntities) {
         // pad the front of the results with nulls representing the incompletes
         array_splice($this->results, 0, 0, array_pad(array(), $num_incomplete, null));
         // ...and skip past them
         reset($this->results);
         for ($i = 0; $i < $num_incomplete; $i++) {
             next($this->results);
         }
     }
     if ($this->results) {
         $this->chunkIndex++;
         // let the system know we've jumped past the nulls
         $this->resultIndex = $num_incomplete;
         $this->retrievedResults += $num_results + $num_incomplete;
         if ($num_results == 0) {
             // This fetch was *all* incompletes! We need to fetch until we can either
             // offer at least one row to iterate over, or give up.
             return $this->getNextResultsChunk();
         }
         return true;
     } else {
         return false;
     }
 }