When editing a block and saving changes, is it normal to have a new entry in its table created?

Permalink
I created a block using the excellent Designer Content add-on.

I place the block on a page, edit it, save it. If I check the corresponding db table, there is a new entry (incremented id) that has the information of my edited block.

I had not noticed this behavior before. Has it always been there or is there something wrong with my block? Is this part of how versioning works?

adavis
 
andrew replied on at Permalink Best Answer Reply
andrew
That's how versioning works. Basically, every time you've got an approved version of a page, and you edit a block, a new version of the page is created, and in that new version of the page, a new block object (with a new ID) is created for that block in that position. If you ever roll back you'll go back to the old block object.

Deleting blocks or old versions of pages with old blocks on them will remove this data, but unless the block is deleted in all versions where it appears, it'll keep its data around.
adavis replied on at Permalink Reply
adavis
OK that makes sense I must not have noticed it before. Thanks Andrew!
stephanebeck replied on at Permalink Reply
stephanebeck
I also use the Designer Content add-on and it populates the btDCNews table just fine.

Then I need to get these entries to promote them on my homepage. So I access the DB, select the appropriate table and print the entries titles using the following code:
$rs = $db->query('SELECT * FROM btDCNews');
while($row = $rs->fetchRow()) {
   echo $row['field_2_textbox_text'].'<br />';
}

But I end up with a list of all the versions of ALL the entries titles!

How is it possible to know which one is the current (last) version of each entry?

Could anyone point me in the right direction?
stephanebeck replied on at Permalink Reply
stephanebeck
This question has been answered by Jordan on the "Designer Content" forums:
http://www.concrete5.org/marketplace/addons/designer-content/forums...
BreakfastStudio replied on at Permalink Reply
BreakfastStudio
I also found out about the bID getting incremented and it now makes sense to me.

The only problem I got is, I have a
$this->addHeaderItem($this->buildCss())
which inserts a
<style>#style-{$bID}</style>
block on the header. The problem is when I edit and save a block the bID gets incremented while the
<style>#style-{$bID}</style>
gets left behind.

Ex.
Initially $bID = 76
This is my div
<div id="style-76"</div>


Header is:
<style>#style-76{}</style>


After edit->save
$bID is incremented, hence $bID = 77

Div block style id gets updated
<div id="style-77"</div>


But the problem is the header style does not get incremented.
<style>#style-76{}</style>


Here is my controller.php
public function on_page_view() {
    $this->addHeaderItem($this->buildCSS());
}
public function buildCSS(){
    $content = '#style-'.$this->bID.'{}';
    return $content;
}