public $is_local; // int(4)
public $source; // varchar(32)
public $conversation; // int(4)
- public $lat; // decimal(10,7)
- public $lon; // decimal(10,7)
- public $location_id; // int(4)
- public $location_ns; // int(4)
public $repeat_of; // int(4)
public $verb; // varchar(191) not 255 because utf8mb4 takes more space
public $object_type; // varchar(191) not 255 because utf8mb4 takes more space
'is_local' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'notice was generated by a user'),
'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'),
'conversation' => array('type' => 'int', 'description' => 'id of root notice in this conversation'),
- 'lat' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'),
- 'lon' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'),
- 'location_id' => array('type' => 'int', 'description' => 'location id if possible'),
- 'location_ns' => array('type' => 'int', 'description' => 'namespace for location'),
'repeat_of' => array('type' => 'int', 'description' => 'notice this is a repeat of'),
'object_type' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI representing activity streams object type', 'default' => 'http://activitystrea.ms/schema/1.0/note'),
'verb' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI representing activity streams verb', 'default' => 'http://activitystrea.ms/schema/1.0/post'),
// Clear related records
$this->clearReplies();
+ $this->clearLocation();
$this->clearRepeats();
$this->clearTags();
$this->clearGroupInboxes();
}
}
+ $notloc = new Notice_location();
if (!empty($lat) && !empty($lon)) {
- $notice->lat = $lat;
- $notice->lon = $lon;
+ $notloc->lat = $lat;
+ $notloc->lon = $lon;
}
if (!empty($location_ns) && !empty($location_id)) {
- $notice->location_id = $location_id;
- $notice->location_ns = $location_ns;
+ $notloc->location_id = $location_id;
+ $notloc->location_ns = $location_ns;
}
if (!empty($rendered)) {
// XXX: some of these functions write to the DB
try {
- $notice->insert(); // throws exception on failure
+ $notice->insert(); // throws exception on failure, if successful we have an ->id
+
+ if (($notloc->lat && $notloc->lon) || ($notloc->location_id && $notloc->location_ns)) {
+ $notloc->notice_id = $notice->getID();
+ $notloc->insert(); // store the notice location if it had any information
+ }
+
// If it's not part of a conversation, it's
// the beginning of a new conversation.
if (empty($notice->conversation)) {
}
}
+ $notloc = null;
if ($act->context instanceof ActivityContext) {
- $location = $act->context->location;
- if ($location) {
- $stored->lat = $location->lat;
- $stored->lon = $location->lon;
- if ($location->location_id) {
- $stored->location_ns = $location->location_ns;
- $stored->location_id = $location->location_id;
- }
+ if ($act->context->location instanceof Location) {
+ $notloc = Notice_location::fromLocation($act->context->location);
}
} else {
$act->context = new ActivityContext();
try {
$stored->insert(); // throws exception on error
+
+ if ($notloc instanceof Notice_location) {
+ $notloc->notice_id = $stored->getID();
+ $notloc->insert();
+ }
+
$orig = clone($stored); // for updating later in this try clause
$object = null;
// This is not a reply to something
}
- $ctx->location = $this->getLocation();
+ try {
+ $ctx->location = Notice_location::locFromStored($this);
+ } catch (ServerException $e) {
+ $ctx->location = null;
+ }
$conv = null;
return ($contentlimit > 0 && !empty($content) && (mb_strlen($content) > $contentlimit));
}
- function getLocation()
- {
- $location = null;
-
- if (!empty($this->location_id) && !empty($this->location_ns)) {
- $location = Location::fromId($this->location_id, $this->location_ns);
- }
-
- if (is_null($location)) { // no ID, or Location::fromId() failed
- if (!empty($this->lat) && !empty($this->lon)) {
- $location = Location::fromLatLon($this->lat, $this->lon);
- }
- }
-
- return $location;
- }
-
/**
* Convenience function for posting a repeat of an existing message.
*
$reply->free();
}
+ function clearLocation()
+ {
+ $loc = new Notice_location();
+ $loc->notice_id = $this->id;
+
+ if ($loc->find()) {
+ $loc->delete();
+ }
+ }
+
function clearFiles()
{
$f2p = new File_to_post();
$notice->_setReplies($ids);
}
}
+
+ static public function beforeSchemaUpdate()
+ {
+ $table = strtolower(get_called_class());
+ $schema = Schema::get();
+ $schemadef = $schema->getTableDef($table);
+
+ // 2015-09-04 We move Notice location data to Notice_location
+ // First we see if we have to do this at all
+ if (!isset($schemadef['fields']['lat'])
+ && !isset($schemadef['fields']['lon'])
+ && !isset($schemadef['fields']['location_id'])
+ && !isset($schemadef['fields']['location_ns'])) {
+ // We have already removed the location fields, so no need to migrate.
+ return;
+ }
+ // Then we make sure the Notice_location table is created!
+ $schema->ensureTable('notice_location', Notice_location::schemaDef());
+
+ // Then we continue on our road to migration!
+ echo "\nFound old $table table, moving location data to 'notice_location' table... (this will probably take a LONG time, but can be aborted and continued)";
+
+ $notice = new Notice();
+ $notice->query(sprintf('SELECT id, lat, lon, location_id, location_ns FROM %1$s ' .
+ 'WHERE lat IS NOT NULL ' .
+ 'OR lon IS NOT NULL ' .
+ 'OR location_id IS NOT NULL ' .
+ 'OR location_ns IS NOT NULL',
+ $schema->quoteIdentifier($table)));
+ print "\nFound {$notice->N} notices with location data, inserting";
+ while ($notice->fetch()) {
+ $notloc = Notice_location::getKV('notice_id', $notice->id);
+ if ($notloc instanceof Notice_location) {
+ print "-";
+ continue;
+ }
+ $notloc = new Notice_location();
+ $notloc->notice_id = $notice->id;
+ $notloc->lat= $notice->lat;
+ $notloc->lon= $notice->lon;
+ $notloc->location_id= $notice->location_id;
+ $notloc->location_ns= $notice->location_ns;
+ $notloc->insert();
+ print ".";
+ }
+ print "\n";
+ }
}
$twitter_status['in_reply_to_screen_name'] =
($replier_profile) ? $replier_profile->nickname : null;
- if (isset($notice->lat) && isset($notice->lon)) {
+ try {
+ $notloc = Notice_location::locFromStored($notice);
// This is the format that GeoJSON expects stuff to be in
$twitter_status['geo'] = array('type' => 'Point',
- 'coordinates' => array((float) $notice->lat,
- (float) $notice->lon));
- } else {
+ 'coordinates' => array((float) $notloc->lat,
+ (float) $notloc->lon));
+ } catch (ServerException $e) {
$twitter_status['geo'] = null;
}
$entry['pubDate'] = common_date_rfc2822($notice->created);
$entry['guid'] = $entry['link'];
- if (isset($notice->lat) && isset($notice->lon)) {
+ try {
+ $notloc = Notice_location::locFromStored($notice);
// This is the format that GeoJSON expects stuff to be in.
// showGeoRSS() below uses it for XML output, so we reuse it
$entry['geo'] = array('type' => 'Point',
- 'coordinates' => array((float) $notice->lat,
- (float) $notice->lon));
- } else {
+ 'coordinates' => array((float) $notloc->lat,
+ (float) $notloc->lon));
+ } catch (ServerException $e) {
$entry['geo'] = null;
}
$statuses = array();
if (is_array($notice)) {
- $notice = new ArrayWrapper($notice);
+ //FIXME: make everything calling showJsonTimeline use only Notice objects
+ common_debug('ArrayWrapper avoidance in progress! Beep boop, make showJsonTimeline only receive Notice objects!');
+ $ids = array();
+ foreach ($notice as $n) {
+ $ids[] = $n->getID();
+ }
+ $notice = Notice::multiGet('id', $ids);
}
while ($notice->fetch()) {
$this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
$this->element('foaf:maker', array('rdf:resource' => $creator_uri));
$this->element('sioc:has_creator', array('rdf:resource' => $creator_uri.'#acct'));
- $location = $notice->getLocation();
- if ($location && isset($location->lat) && isset($location->lon)) {
- $location_uri = $location->getRdfURL();
- $attrs = array('geo:lat' => $location->lat,
- 'geo:long' => $location->lon);
- if (strlen($location_uri)) {
- $attrs['rdf:resource'] = $location_uri;
+ try {
+ $location = Notice_location::locFromStored($notice);
+ if (isset($location->lat) && isset($location->lon)) {
+ $location_uri = $location->getRdfURL();
+ $attrs = array('geo:lat' => $location->lat,
+ 'geo:long' => $location->lon);
+ if (strlen($location_uri)) {
+ $attrs['rdf:resource'] = $location_uri;
+ }
+ $this->element('statusnet:origin', $attrs);
}
- $this->element('statusnet:origin', $attrs);
+ } catch (ServerException $e) {
+ // No result, so no location data
}
$this->element('statusnet:postIcon', array('rdf:resource' => $profile->avatarUrl()));
$this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));