Sure thing, Low.
The general pseudo-code logic is the same as for templates:
$row = $db->get($name);
$file = $fs->get($name);
if ( ! $row && ! $file)
{
return NULL;
}
if ( ! $file || $file->edit_date < $row->edit_date)
{
write_to_file($row);
}
if ( ! $row || $file->edit_date > $row->edit_date)
{
insert_or_update_row_with($file);
}
return $row;
This runs whenever a model entity is retrieved. There’s a special getAll()
method on those models which grabs all db rows and then scans the directory for new files and adds them to the result collection. That method is used on the frontend request to fetch all snippets/gvs and on the cp listing pages.
Otherwise we use the models as usual - there is no way to retrieve one of these models without getting the latest data. When saving we update the file and the row, if necessary. And lastly, deleting the model also deletes the file (the reverse is not true).
Hope that helps!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.