if ($dry) { echo " - skipping\n"; } else { echo " - removing bogus ostatus_profile entry..."; $evil = Ostatus_profile::staticGet('uri', $uri); $evil->delete(); echo " ok\n"; } } echo "\n"; // And there may be user_group entries remaining where we've already killed // the ostatus_profile. These were "harmless" until our lookup started actually // using the uri field, at which point we can clearly see it breaks stuff. echo "Checking for leftover bogus user_group.uri entries obscuring local_group entries...\n"; $group = new User_group(); $group->joinAdd(array('id', 'local_group:group_id'), 'LEFT'); $group->whereAdd('group_id IS NULL'); $marker = mt_rand(31337, 31337000); $groupTemplate = common_local_url('groupbyid', array('id' => $marker)); $encGroup = $group->escape($groupTemplate, true); $encGroup = str_replace($marker, '%', $encGroup); echo " LIKE '{$encGroup}'\n"; $group->whereAdd("uri LIKE '{$encGroup}'"); $group->find(); $count = $group->N; echo "Found {$count}...\n"; while ($group->fetch()) { $uri = $group->uri; if (preg_match('!/group/(\\d+)/id!', $uri, $matches)) { $id = intval($matches[1]); $local = Local_group::staticGet('group_id', $id);
function getGroups() { $group = new User_group(); // Disable this to get global group searches $group->joinAdd(array('id', 'local_group:group_id')); $order = false; if (!empty($this->q)) { $wheres = array('nickname', 'fullname', 'homepage', 'description', 'location'); foreach ($wheres as $where) { // Double % because of sprintf $group->whereAdd(sprintf('LOWER(%1$s.%2$s) LIKE LOWER("%%%3$s%%")', $group->escapedTableName(), $where, $group->escape($this->q)), 'OR'); } $order = sprintf('%1$s.%2$s %3$s', $group->escapedTableName(), $this->getSortKey('created'), $this->reverse ? 'DESC' : 'ASC'); } else { // User is browsing via AlphaNav switch ($this->filter) { case 'all': // NOOP break; case '0-9': $group->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s', $group->escapedTableName(), 'nickname', $group->_quote("0"), $group->_quote("9"))); break; default: $group->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s', $group->escapedTableName(), 'nickname', $group->_quote($this->filter))); } $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC', $group->escapedTableName(), $this->getSortKey('nickname'), $this->reverse ? 'DESC' : 'ASC', 'nickname'); } $offset = ($this->page - 1) * PROFILES_PER_PAGE; $limit = PROFILES_PER_PAGE + 1; $group->selectAdd(); $group->selectAdd('profile_id'); $group->orderBy($order); $group->limit($offset, $limit); $group->find(); return Profile::multiGet('id', $group->fetchAll('profile_id')); }