Move notice location data to Notice_location
Will probably take a _long_ time to do scripts/upgrade.php but don't worry, it can be aborted and resumed.
This commit is contained in:
parent
476197569f
commit
3c86542a40
@ -65,10 +65,6 @@ class Notice extends Managed_DataObject
|
|||||||
public $is_local; // int(4)
|
public $is_local; // int(4)
|
||||||
public $source; // varchar(32)
|
public $source; // varchar(32)
|
||||||
public $conversation; // int(4)
|
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 $repeat_of; // int(4)
|
||||||
public $verb; // varchar(191) not 255 because utf8mb4 takes more space
|
public $verb; // varchar(191) not 255 because utf8mb4 takes more space
|
||||||
public $object_type; // varchar(191) not 255 because utf8mb4 takes more space
|
public $object_type; // varchar(191) not 255 because utf8mb4 takes more space
|
||||||
@ -93,10 +89,6 @@ class Notice extends Managed_DataObject
|
|||||||
'is_local' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'notice was generated by a user'),
|
'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"'),
|
'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'),
|
'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'),
|
'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'),
|
'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'),
|
'verb' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI representing activity streams verb', 'default' => 'http://activitystrea.ms/schema/1.0/post'),
|
||||||
@ -196,6 +188,7 @@ class Notice extends Managed_DataObject
|
|||||||
// Clear related records
|
// Clear related records
|
||||||
|
|
||||||
$this->clearReplies();
|
$this->clearReplies();
|
||||||
|
$this->clearLocation();
|
||||||
$this->clearRepeats();
|
$this->clearRepeats();
|
||||||
$this->clearTags();
|
$this->clearTags();
|
||||||
$this->clearGroupInboxes();
|
$this->clearGroupInboxes();
|
||||||
@ -621,14 +614,15 @@ class Notice extends Managed_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$notloc = new Notice_location();
|
||||||
if (!empty($lat) && !empty($lon)) {
|
if (!empty($lat) && !empty($lon)) {
|
||||||
$notice->lat = $lat;
|
$notloc->lat = $lat;
|
||||||
$notice->lon = $lon;
|
$notloc->lon = $lon;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($location_ns) && !empty($location_id)) {
|
if (!empty($location_ns) && !empty($location_id)) {
|
||||||
$notice->location_id = $location_id;
|
$notloc->location_id = $location_id;
|
||||||
$notice->location_ns = $location_ns;
|
$notloc->location_ns = $location_ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($rendered)) {
|
if (!empty($rendered)) {
|
||||||
@ -667,7 +661,13 @@ class Notice extends Managed_DataObject
|
|||||||
// XXX: some of these functions write to the DB
|
// XXX: some of these functions write to the DB
|
||||||
|
|
||||||
try {
|
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
|
// If it's not part of a conversation, it's
|
||||||
// the beginning of a new conversation.
|
// the beginning of a new conversation.
|
||||||
if (empty($notice->conversation)) {
|
if (empty($notice->conversation)) {
|
||||||
@ -868,15 +868,10 @@ class Notice extends Managed_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$notloc = null;
|
||||||
if ($act->context instanceof ActivityContext) {
|
if ($act->context instanceof ActivityContext) {
|
||||||
$location = $act->context->location;
|
if ($act->context->location instanceof Location) {
|
||||||
if ($location) {
|
$notloc = Notice_location::fromLocation($act->context->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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$act->context = new ActivityContext();
|
$act->context = new ActivityContext();
|
||||||
@ -903,6 +898,12 @@ class Notice extends Managed_DataObject
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$stored->insert(); // throws exception on error
|
$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
|
$orig = clone($stored); // for updating later in this try clause
|
||||||
|
|
||||||
$object = null;
|
$object = null;
|
||||||
@ -1844,7 +1845,11 @@ class Notice extends Managed_DataObject
|
|||||||
// This is not a reply to something
|
// 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;
|
$conv = null;
|
||||||
|
|
||||||
@ -2090,23 +2095,6 @@ class Notice extends Managed_DataObject
|
|||||||
return ($contentlimit > 0 && !empty($content) && (mb_strlen($content) > $contentlimit));
|
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.
|
* Convenience function for posting a repeat of an existing message.
|
||||||
*
|
*
|
||||||
@ -2277,6 +2265,16 @@ class Notice extends Managed_DataObject
|
|||||||
$reply->free();
|
$reply->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearLocation()
|
||||||
|
{
|
||||||
|
$loc = new Notice_location();
|
||||||
|
$loc->notice_id = $this->id;
|
||||||
|
|
||||||
|
if ($loc->find()) {
|
||||||
|
$loc->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clearFiles()
|
function clearFiles()
|
||||||
{
|
{
|
||||||
$f2p = new File_to_post();
|
$f2p = new File_to_post();
|
||||||
@ -2885,4 +2883,51 @@ class Notice extends Managed_DataObject
|
|||||||
$notice->_setReplies($ids);
|
$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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,12 +366,13 @@ class ApiAction extends Action
|
|||||||
$twitter_status['in_reply_to_screen_name'] =
|
$twitter_status['in_reply_to_screen_name'] =
|
||||||
($replier_profile) ? $replier_profile->nickname : null;
|
($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
|
// This is the format that GeoJSON expects stuff to be in
|
||||||
$twitter_status['geo'] = array('type' => 'Point',
|
$twitter_status['geo'] = array('type' => 'Point',
|
||||||
'coordinates' => array((float) $notice->lat,
|
'coordinates' => array((float) $notloc->lat,
|
||||||
(float) $notice->lon));
|
(float) $notloc->lon));
|
||||||
} else {
|
} catch (ServerException $e) {
|
||||||
$twitter_status['geo'] = null;
|
$twitter_status['geo'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,13 +548,14 @@ class ApiAction extends Action
|
|||||||
$entry['pubDate'] = common_date_rfc2822($notice->created);
|
$entry['pubDate'] = common_date_rfc2822($notice->created);
|
||||||
$entry['guid'] = $entry['link'];
|
$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.
|
// This is the format that GeoJSON expects stuff to be in.
|
||||||
// showGeoRSS() below uses it for XML output, so we reuse it
|
// showGeoRSS() below uses it for XML output, so we reuse it
|
||||||
$entry['geo'] = array('type' => 'Point',
|
$entry['geo'] = array('type' => 'Point',
|
||||||
'coordinates' => array((float) $notice->lat,
|
'coordinates' => array((float) $notloc->lat,
|
||||||
(float) $notice->lon));
|
(float) $notloc->lon));
|
||||||
} else {
|
} catch (ServerException $e) {
|
||||||
$entry['geo'] = null;
|
$entry['geo'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,7 +999,13 @@ class ApiAction extends Action
|
|||||||
$statuses = array();
|
$statuses = array();
|
||||||
|
|
||||||
if (is_array($notice)) {
|
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()) {
|
while ($notice->fetch()) {
|
||||||
|
@ -368,18 +368,19 @@ class NoticeListItem extends Widget
|
|||||||
*/
|
*/
|
||||||
function showNoticeLocation()
|
function showNoticeLocation()
|
||||||
{
|
{
|
||||||
$id = $this->notice->id;
|
return;
|
||||||
|
try {
|
||||||
$location = $this->notice->getLocation();
|
$location = Notice_location::locFromStored($this->notice);
|
||||||
|
} catch (NoResultException $e) {
|
||||||
if (empty($location)) {
|
return;
|
||||||
|
} catch (ServerException $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $location->getName();
|
$name = $location->getName();
|
||||||
|
|
||||||
$lat = $this->notice->lat;
|
$lat = $location->lat;
|
||||||
$lon = $this->notice->lon;
|
$lon = $location->lon;
|
||||||
$latlon = (!empty($lat) && !empty($lon)) ? $lat.';'.$lon : '';
|
$latlon = (!empty($lat) && !empty($lon)) ? $lat.';'.$lon : '';
|
||||||
|
|
||||||
if (empty($name)) {
|
if (empty($name)) {
|
||||||
|
@ -216,8 +216,9 @@ class Rss10Action extends ManagedAction
|
|||||||
$this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
|
$this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
|
||||||
$this->element('foaf:maker', array('rdf:resource' => $creator_uri));
|
$this->element('foaf:maker', array('rdf:resource' => $creator_uri));
|
||||||
$this->element('sioc:has_creator', array('rdf:resource' => $creator_uri.'#acct'));
|
$this->element('sioc:has_creator', array('rdf:resource' => $creator_uri.'#acct'));
|
||||||
$location = $notice->getLocation();
|
try {
|
||||||
if ($location && isset($location->lat) && isset($location->lon)) {
|
$location = Notice_location::locFromStored($notice);
|
||||||
|
if (isset($location->lat) && isset($location->lon)) {
|
||||||
$location_uri = $location->getRdfURL();
|
$location_uri = $location->getRdfURL();
|
||||||
$attrs = array('geo:lat' => $location->lat,
|
$attrs = array('geo:lat' => $location->lat,
|
||||||
'geo:long' => $location->lon);
|
'geo:long' => $location->lon);
|
||||||
@ -226,6 +227,9 @@ class Rss10Action extends ManagedAction
|
|||||||
}
|
}
|
||||||
$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('statusnet:postIcon', array('rdf:resource' => $profile->avatarUrl()));
|
||||||
$this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
|
$this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
|
||||||
if ($notice->reply_to) {
|
if ($notice->reply_to) {
|
||||||
|
@ -120,9 +120,11 @@ class MapAction extends Action
|
|||||||
$jsonArray = array();
|
$jsonArray = array();
|
||||||
|
|
||||||
while ($this->notice->fetch()) {
|
while ($this->notice->fetch()) {
|
||||||
if (!empty($this->notice->lat) && !empty($this->notice->lon)) {
|
try {
|
||||||
$jsonNotice = $this->noticeAsJson($this->notice);
|
$notloc = Notice_location::locFromStored($this->notice);
|
||||||
$jsonArray[] = $jsonNotice;
|
$jsonArray[] = $this->noticeAsJson($this->notice);
|
||||||
|
} catch (ServerException $e) {
|
||||||
|
// no location data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user