Search code examples
phpconcrete5

How can I determine the date a block was added in Concrete5?


$block->getBlockDateAdded() and $block->getBlockDateLastModified() both return the same timestamp, the one of last modification (in all my tests).

This might be because on every modification of a block Concrete5 creates a new version, so $block->getBlockDateAdded() seem to return the date the particular version was added, which so is the same as the last modification. But what is the use then?

And more important: Is there a way to get the "real" date the block was added, means the first version is created?


Solution

  • I don't think this is possible, because version history is kept with the Collection (Page), and as you mention, a new block record is created for every new page version.

    Looking at the CollectionVersionBlocks table in the database, I don't see any key that could be used to associate one block with a prior version -- so there's no way to backtrack through the Collection Versions and see where the first existence of the block happens (you could guess based on the block type and the area, but this wouldn't be certain because a user could have moved it from one area to another, or there could be more than one block of the same type on the page).

    EDIT: I found a solution in the forums that might achieve this:

    private function find_prev_bID($bID) {
        if (empty($bID)){
            return;
        }
        $db = Loader::db();
        $prev_bID = $db->GetOne( 'SELECT originalBID FROM BlockRelations WHERE bID = ? AND relationType = ?', array($bID, 'DUPLICATE') );
        return $prev_bID;
    }