|
|
@ -3,15 +3,44 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace App\Tables; |
|
|
|
namespace App\Tables; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\Revision; |
|
|
|
|
|
|
|
use App\Models\Table; |
|
|
|
|
|
|
|
use Illuminate\Queue\SerializesModels; |
|
|
|
|
|
|
|
use ReflectionClass; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Object representing a set of table modifications |
|
|
|
* Object representing a set of table modifications |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class Changeset |
|
|
|
class Changeset |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
use SerializesModels; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const object_excluded_properties = [ |
|
|
|
|
|
|
|
'revision', |
|
|
|
|
|
|
|
'table', |
|
|
|
|
|
|
|
'note', |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @var Revision - base revision this changeset belongs to |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public $revision; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @var Table - table this changeset belongs to |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public $table; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @var string - user's note attached to this changeset (future proposal) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public $note; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Rows whose content changed |
|
|
|
* Rows whose content changed, identified by _id. |
|
|
|
|
|
|
|
* Only changed values are to be filled. Columns are identified by GCIDs |
|
|
|
* |
|
|
|
* |
|
|
|
* @var array|null - [GRID -> values, ...] |
|
|
|
* @var array|null - [[_id:…, …], …] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $rowUpdates; |
|
|
|
public $rowUpdates; |
|
|
|
|
|
|
|
|
|
|
@ -19,7 +48,7 @@ class Changeset |
|
|
|
* New rows in the full Row::data format, including GRIDs. |
|
|
|
* New rows in the full Row::data format, including GRIDs. |
|
|
|
* Values are identified by GCIDs from previously defined, or new columns. |
|
|
|
* Values are identified by GCIDs from previously defined, or new columns. |
|
|
|
* |
|
|
|
* |
|
|
|
* @var array|null - [[_id:..., ...], [..., ...], ...] |
|
|
|
* @var array|null - [[_id:…, …], …] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $newRows; |
|
|
|
public $newRows; |
|
|
|
|
|
|
|
|
|
|
@ -41,7 +70,7 @@ class Changeset |
|
|
|
/** |
|
|
|
/** |
|
|
|
* New columns in the full format, including GCIDs |
|
|
|
* New columns in the full format, including GCIDs |
|
|
|
* |
|
|
|
* |
|
|
|
* @var array|null - [[id:..., ...], [..., ...], ...] |
|
|
|
* @var array|null - [[id:…, …], …] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $newColumns; |
|
|
|
public $newColumns; |
|
|
|
|
|
|
|
|
|
|
@ -66,4 +95,65 @@ class Changeset |
|
|
|
* @var int[]|null - GCIDs |
|
|
|
* @var int[]|null - GCIDs |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $removedColumns; |
|
|
|
public $removedColumns; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function walkProps() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$properties = (new ReflectionClass($this))->getProperties(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($properties as $property) { |
|
|
|
|
|
|
|
if (in_array($property->name, self::object_excluded_properties)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yield $property->name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Reconstruct from a object, such as one found in Proposal. |
|
|
|
|
|
|
|
* Note that the fromProposal() method should be used when the |
|
|
|
|
|
|
|
* proposal is available, as it populates additional fields. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param \stdClass $changes |
|
|
|
|
|
|
|
* @return Changeset |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function fromObject($changes) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$changeset = new Changeset(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($changeset->walkProps() as $prop) { |
|
|
|
|
|
|
|
if (isset($changes->$prop)) { |
|
|
|
|
|
|
|
$changeset->$prop = $changes->$prop; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $changeset; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Serialize to an object format that may be stored in a Proposal. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return \stdClass |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function toObject() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$object = new \stdClass(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->walkProps() as $prop) { |
|
|
|
|
|
|
|
$object->$prop = array_values($this->$prop); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $object; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function hasAnyChanges() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach ($this->walkProps() as $prop) { |
|
|
|
|
|
|
|
if (!empty($this->$prop)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|