-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14212 from jdalsem/activity-last-action
feat(activity): commenting bumps related river activity last action
- Loading branch information
Showing
11 changed files
with
176 additions
and
17 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
engine/classes/Elgg/Comments/UpdateRiverLastActionHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Elgg\Comments; | ||
|
||
/** | ||
* Updates river item last action | ||
* | ||
* @since 5.0 | ||
*/ | ||
class UpdateRiverLastActionHandler { | ||
|
||
/** | ||
* Updates the last action of a related river item | ||
* | ||
* @param \Elgg\Event $event 'create:after', 'river' | ||
* | ||
* @return void | ||
*/ | ||
public function __invoke(\Elgg\Event $event) { | ||
$item = $event->getObject(); | ||
if (!$item instanceof \ElggRiverItem) { | ||
return; | ||
} | ||
|
||
$object = $item->getObjectEntity(); | ||
if (!$object instanceof \ElggComment || $item->action_type !== 'comment') { | ||
return; | ||
} | ||
|
||
// find create river and update the river item | ||
$river = elgg_get_river([ | ||
'object_guid' => $item->target_guid, | ||
'action' => 'create', | ||
'limit' => 1, | ||
]); | ||
if (empty($river)) { | ||
return; | ||
} | ||
|
||
$old_item = $river[0]; | ||
$old_item->updateLastAction($item->getTimePosted()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
engine/schema/migrations/20221110111653_add_river_last_action.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
use Phinx\Db\Adapter\MysqlAdapter; | ||
|
||
final class AddRiverLastAction extends AbstractMigration { | ||
/** | ||
* Adds the river last action column and fills it with the posted timestamp | ||
*/ | ||
public function change(): void { | ||
$table = $this->table('river'); | ||
if ($table->hasColumn('last_action')) { | ||
return; | ||
} | ||
|
||
$table->addColumn('last_action', 'integer', [ | ||
'null' => false, | ||
'limit' => MysqlAdapter::INT_REGULAR, | ||
'precision' => 11, | ||
]); | ||
$table->addIndex(['last_action'], [ | ||
'name' => 'last_action', | ||
'unique' => false, | ||
]); | ||
|
||
$table->update(); | ||
|
||
// copy posted into last_action | ||
$prefix = $this->getAdapter()->getOption('table_prefix'); | ||
|
||
$this->execute("UPDATE {$prefix}river SET last_action = posted"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters