Page MenuHomePhorge

PHP creation of Tasks - problem with Title in feed
Closed, InvalidPublic

Description

I have a small PHP file that creates a Task.

This is just an example that can be placed in the root of Phorge:

create-task.php
<?php
require 'scripts/init/init-script.php';

$task_title = $argv[1];

// Just one random user.
$phorge_user = ( new PhabricatorPeopleQuery() )
  ->setViewer( PhabricatorUser::getOmnipotentUser() )
  ->setLimit( 1 )
  ->executeOne();

$maniphest_transaction_template = new ManiphestTransaction();

// Create a new Task.
$task = ManiphestTask::initializeNewTask($phorge_user);

// Set a title.
$xactions[] = (clone $maniphest_transaction_template)
  ->setTransactionType(ManiphestTaskTitleTransaction::TRANSACTIONTYPE)
  ->setNewValue($task_title);

// Another random action. Set status.
$xactions[] = (clone $maniphest_transaction_template)
  ->setTransactionType(ManiphestTaskStatusTransaction::TRANSACTIONTYPE)
  ->setNewValue(ManiphestTaskStatus::getDefaultClosedStatus());

// Save Task.
$editor = (new ManiphestTransactionEditor())
  ->setActor($phorge_user)
  ->setContentSource(PhabricatorContentSource::newForSource(PhabricatorConsoleContentSource::SOURCECONST))
  ->applyTransactions($task, $xactions);

So I can execute the file and it works:

php create-task.php "Task title"

What happens

But I get this nonsense "renamed" transaction feed in the homepage:

Task creation borked.png (131×532 px, 9 KB)

What should happen instead

I'm quite sure that this should happen instead:

Task creation feed normal.png (131×532 px, 8 KB)

Question

Am I doing something wrong?

If not, maybe we have a bug here:

https://we.phorge.it/source/phorge/browse/master/src/applications/maniphest/xaction/ManiphestTaskTitleTransaction.php;faf43d7edf7b2da743cc900e4ecdca10f64a973f$49

Note that the normal feed in the object page is correct instead. It's just the homepage feed that says "renamed".

Related Objects

Event Timeline

valerio.bozzolan changed the visibility from "Public (No Login Required)" to "Task Author".Mar 11 2024, 18:14
valerio.bozzolan renamed this task from ASD to PHP creation of Tasks - problem with Title in feed.Mar 11 2024, 18:27
valerio.bozzolan triaged this task as Normal priority.
valerio.bozzolan updated the task description. (Show Details)
valerio.bozzolan changed the visibility from "Task Author" to "Public (No Login Required)".

Look into the "is creation xaction" - we had a similar diff recently about creating Revision from raw diff that had a similar behavior.

Thanks avivey. Added this:

// Track creation.
$xactions[] = (clone $maniphest_transaction_template)
  ->setTransactionType(PhabricatorTransactions::TYPE_CREATE);

I could not even reproduce but get an informative error instead:

ak@ac:/var/www/html/phorge/phorge$ php T15754.php "Task title test old"
[2024-03-11 23:45:67] EXCEPTION: (PhabricatorApplicationTransactionStructureException) Attempting to apply a transaction (of class "ManiphestTransaction", with type "title") which has not been constructed correctly: This transaction should generate its oldValue automatically, but has already had one set! at [<phorge>/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php:1826]
arcanist(head=master, ref.master=174bf094ef9f), phorge(head=master, ref.master=faf43d7edf7b)
  #0 PhabricatorApplicationTransactionEditor::validateEditParameters(ManiphestTask, array) called at [<phorge>/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php:1214]
  #1 PhabricatorApplicationTransactionEditor::applyTransactions(ManiphestTask, array) called at [<phorge>/T15754.php:39]