Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions _build/test/Tests/Processors/Element/CategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ public function providerCategoryGetList() {
];
}

/**
* Tests that createdon is set when creating a Category and editedon remains null
*/
public function testCategoryCreateSetsCreatedon() {
/** @var ProcessorResponse $result */
$result = $this->modx->runProcessor(Create::class, [
'category' => 'UnitTestCatTimestamp',
]);
$this->assertTrue($this->checkForSuccess($result), 'Could not create Category for timestamp test');

/** @var modCategory $category */
$category = $this->modx->getObject(modCategory::class, ['category' => 'UnitTestCatTimestamp']);
$this->assertNotNull($category, 'Category not found after creation');

$this->assertNotNull($category->get('createdon'), 'createdon should be set on new Category');
$this->assertNotEmpty($category->get('createdon'), 'createdon should not be empty on new Category');
$this->assertNull($category->get('editedon'), 'editedon should be null on new Category');
}

/**
* Tests the element/category/remove processor, which removes a Category
*
Expand Down
41 changes: 41 additions & 0 deletions _build/test/Tests/Processors/Element/ChunkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,47 @@ public function providerChunkGetList() {
];
}

/**
* Tests that createdon is set when creating a Chunk and editedon remains null
*/
public function testChunkCreateSetsCreatedon() {
$result = $this->modx->runProcessor(Create::class, [
'name' => 'UnitTestChunkTimestamp',
]);
$this->assertTrue($this->checkForSuccess($result), 'Could not create Chunk for timestamp test');

/** @var modChunk $chunk */
$chunk = $this->modx->getObject(modChunk::class, ['name' => 'UnitTestChunkTimestamp']);
$this->assertNotNull($chunk, 'Chunk not found after creation');

$this->assertNotNull($chunk->get('createdon'), 'createdon should be set on new Chunk');
$this->assertNotEmpty($chunk->get('createdon'), 'createdon should not be empty on new Chunk');
$this->assertNull($chunk->get('editedon'), 'editedon should be null on new Chunk');
}

/**
* Tests that createdon is preserved after updating a Chunk
*/
public function testChunkUpdatePreservesCreatedon() {
/** @var modChunk $chunk */
$chunk = $this->modx->getObject(modChunk::class, ['name' => 'UnitTestChunk']);
$this->assertNotNull($chunk, 'UnitTestChunk not found');

$createdon = $chunk->get('createdon');
$this->assertNotNull($createdon, 'createdon should be set on fixture chunk');

$result = $this->modx->runProcessor(Update::class, [
'id' => $chunk->get('id'),
'name' => 'UnitTestChunk',
'description' => 'Updated for timestamp test',
]);
$this->assertTrue($this->checkForSuccess($result), 'Could not update Chunk for timestamp test');

// Re-fetch to get fresh data
$chunk = $this->modx->getObject(modChunk::class, ['name' => 'UnitTestChunk']);
$this->assertEquals($createdon, $chunk->get('createdon'), 'createdon should not change on update');
}

/**
* Tests the element/chunk/remove processor, which removes a Chunk
* @dataProvider providerChunkRemove
Expand Down
20 changes: 20 additions & 0 deletions core/model/schema/modx.mysql.schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@
<field key="parent" dbtype="int" precision="10" phptype="integer" attributes="unsigned" default="0" index="unique" indexgrp="category" />
<field key="category" dbtype="varchar" precision="45" phptype="string" null="false" default="" index="unique" indexgrp="category" />
<field key="rank" dbtype="int" precision="11" phptype="integer" null="false" default="0" index="index" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<index alias="parent" name="parent" primary="false" unique="false" type="BTREE">
<column key="parent" length="" collation="A" null="false" />
Expand Down Expand Up @@ -350,6 +352,8 @@
<field key="properties" dbtype="text" phptype="array" null="true" />
<field key="static" dbtype="tinyint" precision="1" attributes="unsigned" phptype="boolean" null="false" default="0" index="index" />
<field key="static_file" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<alias key="content" field="snippet" />

Expand Down Expand Up @@ -755,6 +759,8 @@
<field key="moduleguid" dbtype="varchar" precision="32" phptype="string" null="false" default="" index="fk" />
<field key="static" dbtype="tinyint" precision="1" attributes="unsigned" phptype="boolean" null="false" default="0" index="index" />
<field key="static_file" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<alias key="content" field="plugincode" />

Expand Down Expand Up @@ -784,6 +790,8 @@
<field key="event" dbtype="varchar" precision="191" phptype="string" null="false" default="" index="pk" />
<field key="priority" dbtype="int" precision="10" phptype="integer" null="false" default="0" index="index" />
<field key="propertyset" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
<column key="pluginid" length="" collation="A" null="false" />
Expand Down Expand Up @@ -1011,6 +1019,8 @@
<field key="moduleguid" dbtype="varchar" precision="32" phptype="string" null="false" default="" index="fk" />
<field key="static" dbtype="tinyint" precision="1" attributes="unsigned" phptype="boolean" null="false" default="0" index="index" />
<field key="static_file" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<alias key="content" field="snippet" />

Expand Down Expand Up @@ -1068,6 +1078,8 @@
<field key="static" dbtype="tinyint" precision="1" attributes="unsigned" phptype="boolean" null="false" default="0" index="index" />
<field key="static_file" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="preview_file" dbtype="varchar" precision="191" phptype="string" null="false" default="" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<index alias="templatename" name="templatename" primary="false" unique="true" type="BTREE">
<column key="templatename" length="" collation="A" null="false" />
Expand Down Expand Up @@ -1113,6 +1125,8 @@
<field key="output_properties" dbtype="text" phptype="array" null="true" />
<field key="static" dbtype="tinyint" precision="1" attributes="unsigned" phptype="boolean" null="false" default="0" index="index" />
<field key="static_file" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<alias key="content" field="default_text" />

Expand Down Expand Up @@ -1151,6 +1165,8 @@
<field key="tmplvarid" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
<field key="contentid" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
<field key="value" dbtype="mediumtext" phptype="string" null="false" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<index alias="tmplvarid" name="tmplvarid" primary="false" unique="false" type="BTREE">
<column key="tmplvarid" length="" collation="A" null="false" />
Expand All @@ -1170,6 +1186,8 @@
<object class="modTemplateVarResourceGroup" table="site_tmplvar_access" extends="xPDO\Om\xPDOSimpleObject">
<field key="tmplvarid" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="documentgroup" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<index alias="tmplvar_template" name="tmplvar_template" type="BTREE">
<column key="tmplvarid" length="" collation="A" null="false" />
Expand All @@ -1184,6 +1202,8 @@
<field key="tmplvarid" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="pk" />
<field key="templateid" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" index="pk" />
<field key="rank" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" default="NULL" attributes="ON UPDATE CURRENT_TIMESTAMP" />

<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
<column key="tmplvarid" length="" collation="A" null="false" />
Expand Down
4 changes: 4 additions & 0 deletions core/src/Revolution/modCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public function save($cacheFlag = null)
{
$isNew = $this->isNew();

if ($isNew && !$this->get('createdon')) {
$this->set('createdon', date('Y-m-d H:i:s'));
}

if ($this->xpdo instanceof modX) {
$this->xpdo->invokeEvent('OnCategoryBeforeSave', [
'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
Expand Down
4 changes: 4 additions & 0 deletions core/src/Revolution/modElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ public function get($k, $format = null, $formatTemplate = null)
*/
public function save($cacheFlag = null)
{
if ($this->isNew() && !$this->get('createdon')) {
$this->set('createdon', date('Y-m-d H:i:s'));
}

if (!$this->getOption(xPDO::OPT_SETUP)) {
if ($this->staticSourceChanged()) {
$staticContent = $this->getFileContent();
Expand Down
18 changes: 17 additions & 1 deletion core/src/Revolution/mysql/modCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class modCategory extends \MODX\Revolution\modCategory
'parent' => 0,
'category' => '',
'rank' => 0,
'createdon' => NULL,
'editedon' => NULL,
),
'fieldMeta' =>
array (
Expand All @@ -43,7 +45,7 @@ class modCategory extends \MODX\Revolution\modCategory
'index' => 'unique',
'indexgrp' => 'category',
),
'rank' =>
'rank' =>
array (
'dbtype' => 'int',
'precision' => '11',
Expand All @@ -52,6 +54,20 @@ class modCategory extends \MODX\Revolution\modCategory
'default' => 0,
'index' => 'index',
),
'createdon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
),
'editedon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
'default' => NULL,
'attributes' => 'ON UPDATE CURRENT_TIMESTAMP',
),
),
'indexes' =>
array (
Expand Down
18 changes: 17 additions & 1 deletion core/src/Revolution/mysql/modChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class modChunk extends \MODX\Revolution\modChunk
'properties' => NULL,
'static' => 0,
'static_file' => '',
'createdon' => NULL,
'editedon' => NULL,
),
'fieldMeta' =>
array (
Expand Down Expand Up @@ -103,14 +105,28 @@ class modChunk extends \MODX\Revolution\modChunk
'default' => 0,
'index' => 'index',
),
'static_file' =>
'static_file' =>
array (
'dbtype' => 'varchar',
'precision' => '255',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'createdon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
),
'editedon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
'default' => NULL,
'attributes' => 'ON UPDATE CURRENT_TIMESTAMP',
),
),
'fieldAliases' =>
array (
Expand Down
18 changes: 17 additions & 1 deletion core/src/Revolution/mysql/modPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class modPlugin extends \MODX\Revolution\modPlugin
'moduleguid' => '',
'static' => 0,
'static_file' => '',
'createdon' => NULL,
'editedon' => NULL,
),
'fieldMeta' =>
array (
Expand Down Expand Up @@ -88,14 +90,28 @@ class modPlugin extends \MODX\Revolution\modPlugin
'default' => 0,
'index' => 'index',
),
'static_file' =>
'static_file' =>
array (
'dbtype' => 'varchar',
'precision' => '255',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'createdon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
),
'editedon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
'default' => NULL,
'attributes' => 'ON UPDATE CURRENT_TIMESTAMP',
),
),
'fieldAliases' =>
array (
Expand Down
18 changes: 17 additions & 1 deletion core/src/Revolution/mysql/modPluginEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class modPluginEvent extends \MODX\Revolution\modPluginEvent
'event' => '',
'priority' => 0,
'propertyset' => 0,
'createdon' => NULL,
'editedon' => NULL,
),
'fieldMeta' =>
array (
Expand Down Expand Up @@ -51,7 +53,7 @@ class modPluginEvent extends \MODX\Revolution\modPluginEvent
'default' => 0,
'index' => 'index',
),
'propertyset' =>
'propertyset' =>
array (
'dbtype' => 'int',
'precision' => '10',
Expand All @@ -61,6 +63,20 @@ class modPluginEvent extends \MODX\Revolution\modPluginEvent
'default' => 0,
'index' => 'index',
),
'createdon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
),
'editedon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
'default' => NULL,
'attributes' => 'ON UPDATE CURRENT_TIMESTAMP',
),
),
'indexes' =>
array (
Expand Down
20 changes: 18 additions & 2 deletions core/src/Revolution/mysql/modSnippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class modSnippet extends \MODX\Revolution\modSnippet
'moduleguid' => '',
'static' => 0,
'static_file' => '',
'createdon' => NULL,
'editedon' => NULL,
),
'fieldMeta' =>
array (
Expand Down Expand Up @@ -75,16 +77,30 @@ class modSnippet extends \MODX\Revolution\modSnippet
'default' => 0,
'index' => 'index',
),
'static_file' =>
'static_file' =>
array (
'dbtype' => 'varchar',
'precision' => '255',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'createdon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
),
'editedon' =>
array (
'dbtype' => 'datetime',
'phptype' => 'datetime',
'null' => true,
'default' => NULL,
'attributes' => 'ON UPDATE CURRENT_TIMESTAMP',
),
),
'fieldAliases' =>
'fieldAliases' =>
array (
'content' => 'snippet',
),
Expand Down
Loading
Loading