Skip to content

Commit

Permalink
improved indexes. added version change update on db and update on get…
Browse files Browse the repository at this point in the history
…DatabaseSchema. Removed comments and debug. Pushed version.
  • Loading branch information
elabx committed Jul 3, 2024
1 parent 31c4527 commit c594f01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion FieldtypeRecurringDates.info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Recurring Dates",
"version": "0.0.1-alpha4",
"version": "0.0.1",
"summary": "Field that stores recurring events from RRule input.",
"icon": "calendar-o",
"installs": "InputfieldRecurringDates",
Expand Down
21 changes: 14 additions & 7 deletions FieldtypeRecurringDates.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ use RRule\RRule;
class FieldtypeRecurringDates extends FieldtypeMulti
{




const defaultLimit = 10;
const EXTRAS_TABLE_NAME_SUFFIX = '_extras';
const EXTRAS_TABLE_COLS = [
Expand Down Expand Up @@ -60,7 +57,7 @@ class FieldtypeRecurringDates extends FieldtypeMulti
$field_name = $event->fields->get($field)->name;
$page = $event->pages->get($page);
$value = $page->$field_name("start=$start, limit=$limit, sort=data");
bd($value->occurrences);

return $value->occurrences;
}

Expand All @@ -72,7 +69,6 @@ class FieldtypeRecurringDates extends FieldtypeMulti
*/
public function hookAfterFieldAdded($event)
{
bd($event);
$item = $event->arguments(0);
if ($item->type->name == $this->name) {
$table_name = $this->getExtrasTableName($item);
Expand Down Expand Up @@ -154,9 +150,8 @@ class FieldtypeRecurringDates extends FieldtypeMulti
$schema['id'] = 'INT UNSIGNED NOT NULL AUTO_INCREMENT';
$schema['data'] = 'datetime NOT NULL';
$schema['keys']['primary'] = 'PRIMARY KEY (id)';
$schema['keys']['pages_id'] = 'UNIQUE (pages_id, sort)';
$schema['keys']['pages_id_sort_data'] = 'UNIQUE (pages_id, sort, data)';
$schema['keys']['data'] = 'KEY data (data)';
// $schema['excluded'] = 'tinyint NOT NULL';
return $schema;
}

Expand Down Expand Up @@ -279,6 +274,7 @@ class FieldtypeRecurringDates extends FieldtypeMulti
$this->saveSettings($page, $field, $value);
foreach ($value->rrule as $date) {
$occurrence_date = new Occurrence();
// TODO
// $occurrence_date->excluded = false;
$occurrence_date->date = $date;
$value->occurrences->add($occurrence_date);
Expand Down Expand Up @@ -531,4 +527,15 @@ class FieldtypeRecurringDates extends FieldtypeMulti
return $a;
}

public function ___upgrade($fromVersion, $toVersion){
if($fromVersion == "0.0.1-alpha4" && $toVersion == "0.0.1"){
foreach($this->fields->find("type={$this->name}") as $field){
$table = $field->getTable();
$update_schema = "ALTER TABLE `{$table}`ADD UNIQUE `pages_id_sort_data` (`pages_id`, `sort`, `data`), DROP INDEX `pages_id`";
$pdo = $this->database->prepare($update_schema);
$pdo->execute();
}
}
}

}

0 comments on commit c594f01

Please sign in to comment.