$q = PluginDataQuery::create()->filterByPlugin($plugin)->filterByKey($key)->findOne(); if (is_null($data['value'])) { // remove value if ($q) { $q->delete(); } ok(); } else { // udpate value if (!$q) { $q = new PluginData(); $q->setPlugin($plugin); $q->setKey($key); } $q->setData($data['value']); $q->setStoredAt(time()); $q->save(); ok($q->toArray()); } } else { // change plugin permission if ($org->hasPlugin($plugin)) { if ($op == 'remove' || $op == 'toggle') { $org->removePlugin($plugin); } } else { if ($op == '' || $op == 'toggle') { $org->addPlugin($plugin); } } $org->save();
/** * allows the plugin to persistently store arbitrary data * * @param key string a key * @param data json_seriazable the data thats being stored. must be json serializable * @param single boolean if set, any existing value with the same key will be overwritten */ public function storeData($key, $data, $single = true) { if ($single) { // remove any existing value PluginDataQuery::create()->filterByPlugin($this->getPluginOM())->filterByKey($key)->delete(); } $pd = new PluginData(); $pd->setPlugin($this->getPluginOM()); $pd->setKey($key); $pd->setData($data); $pd->setStoredAt(time()); $pd->save(); }