public function _createStreamDataWithEntity($entity, $entity_type) { // if(!$entity_type){ // $entity_type = get_class($entity); // } $entity_type_p = $entity_type . 's'; // debug($entity); // $game = $this->_contains($game)->first(); $success = $entity->format(null, 'feed_push'); if (!$success) { Debugger::log('It failed after formatting the game'); return false; } $base_data = ["object" => $entity_type . ":" . $entity->id, 'type' => "feed-" . strtolower($entity_type_p), 'foreign_id' => $entity_type . ":" . $entity->id, 'display' => $entity->display]; if ($entity_type == 'Game') { $specific_data = ["verb" => strtolower($entity->game_type_name), 'first_user_image' => $entity->winner_image, 'first_user_id' => $entity->winner_id, 'first_user_score' => $entity->winner_points, 'second_user_image' => $entity->loser_image, 'second_user_id' => $entity->loser_id, 'second_user_score' => $entity->loser_points, 'game_type_name' => $entity->game_type_name, 'time' => $entity->created]; } else { if ($entity_type == 'Friendship') { $specific_data = ["verb" => "friend", 'first_user_id' => $entity->first_user_id, 'first_user_image' => $entity->first_user_image, 'second_user_id' => $entity->second_user_id, 'second_user_image' => $entity->second_user_image, 'time' => $entity->modified]; } else { return false; } } $base_data = array_merge($base_data, $specific_data); return $base_data; }
/** * @param string $userId * @return bool */ public function createAdmin($userId) { $teamMembership = TableRegistry::get('TeamMemberships'); $adminship = new TeamMembership(['role' => 'admin', 'team_id' => $this->id, 'member_id' => $userId]); $isCurrentMember = $teamMembership->find()->where(['member_id' => $userId, 'team_id' => $this->id])->first(); Debugger::log($isCurrentMember); if (!empty($isCurrentMember)) { $adminship->id = $isCurrentMember->id; } if (!$teamMembership->save($adminship)) { return false; } return true; }
public function ajaxResponseStatusCallback($uniqueId) { try { $DEFAULT_URL = 'https://ens.firebaseio.com/'; $DEFAULT_TOKEN = Configure::read('Firebase.token'); $DEFAULT_PATH = '/call'; $firebase = new \Firebase\FirebaseLib($DEFAULT_URL, $DEFAULT_TOKEN); $sendQueueTable = TableRegistry::get('SendQueues'); $sendQueue = $sendQueueTable->find()->where(['unique_id' => $uniqueId])->contain(['Audios']); if (!$sendQueue->count()) { throw new Exception('Cannot find queue.'); } $queue = $sendQueue->all()->first(); // Get number id $numberId = $firebase->get($DEFAULT_PATH . '/' . $queue->send_queue_id . '/number_match/' . $this->request->data['CallSid']); // Set as Success $firebase->set($DEFAULT_PATH . '/' . $queue->send_queue_id . '/numbers/' . $numberId . '/call_status', 3); Debugger::log($this->request->data); $response['status'] = 1; } catch (\Exception $ex) { $response['status'] = 0; $response['message'] = $ex->getMessage(); } $this->set(compact('response')); $this->set('_serialize', ['response']); }
/** * test log() depth * * @return void */ public function testLogDepth() { $mock = $this->getMock('Cake\\Log\\Engine\\BaseLog', ['log']); Log::config('test', ['engine' => $mock]); $mock->expects($this->at(0))->method('log')->with('debug', $this->logicalAnd($this->stringContains('DebuggerTest::testLog'), $this->stringContains('test'), $this->logicalNot($this->stringContains('val')))); $val = ['test' => ['key' => 'val']]; Debugger::log($val, 'debug', 0); }
/** * Triggered after plugin is removed from DB and after its directory was removed. * * @param \Cake\Event\Event $event * @return void */ public function afterUninstall(Event $event) { Debugger::log('afterUninstall: ' . $this->_line()); }
/** * Start the shell and interactive console. * * @return int|void */ public function main() { $sa_table = TableRegistry::get('Friendships'); $fitbit_accounts = $sa_table->find()->matching('Froms.SocialAccounts', function ($q) { return $q->where(['provider' => 'Fitbit']); })->contain(['Tos']); $game = TableRegistry::get('Games'); $controller = new AppController(); $stream = $controller->loadComponent('Stream'); $tm_table = TableRegistry::get('TempMembers'); debug(Time::now()->i18nFormat('yyyy-MM-dd 00:00:00')); $lr_table = TableRegistry::get('LinkedRecords'); foreach ($fitbit_accounts as $fitbit_account) { //find all pairings of fitbit friends if (empty($social_accounts = $fitbit_account['to']['social_accounts'])) { continue; } $fitbit_social_account = false; foreach ($social_accounts as $social_account) { if ($social_account->provider == 'Fitbit') { $fitbit_social_account = $social_account->id; } } if (!$fitbit_social_account) { continue; } // //find todays linked record $to = $lr_table->find()->where(['social_account_id' => $fitbit_social_account, 'associated_date' => Time::now()->i18nFormat('yyyy-MM-dd 00:00:00')]); if (!$to->first()) { continue; } // // debug($to->first()); // return; $to_mem = ['member_id' => $fitbit_account->to->id, 'points' => null, 'role' => 'member', 'linked_record_id' => $to->first()->id]; if (empty($social_accounts = $fitbit_account['from']['social_accounts'])) { continue; } $fitbit_social_account = false; foreach ($social_accounts as $social_account) { if ($social_account->provider == 'Fitbit') { $fitbit_social_account = $social_account->id; } } if (!$fitbit_social_account) { continue; } $from = $lr_table->find()->where(['social_account_id' => $fitbit_social_account, 'associated_date' => Time::now()->i18nFormat('yyyy-MM-dd 00:00:00')]); if (!$from->first()) { continue; } $from_mem = ['member_id' => $fitbit_account->from->id, 'points' => null, 'role' => 'member', 'linked_record_id' => $from->first()->id]; $game_array = ['status' => 'complete', 'score_type' => 'score', 'game_type_id' => '81e376fa-9f08-4814-82e7-00a2cbf1935b', 'game_memberships' => [$to_mem, $from_mem]]; $new_game = $game->newEntity($game_array); if ($game->save($new_game)) { $base_data = $stream->_createStreamData($new_game->id, 'Game'); Debugger::log($base_data); if ($base_data) { if (!$tm_table->exists(['id' => $base_data['first_user_id']])) { $stream->_pushToStream($base_data, $base_data['first_user_id']); } if (!$tm_table->exists(['id' => $base_data['second_user_id']])) { $stream->_pushToStream($base_data, $base_data['second_user_id']); } } } } }
public function _beforeRender_View(\Cake\Event\Event $event) { Debugger::log($this->request->query('pane')); $this->set('pane', $this->request->query('pane') ? $this->request->query('pane') : 'feed'); }
/** * Stores some bootstrap-handy information into a persistent file. * * Information is stored in `TMP/snapshot.php` file, it contains * useful information such as enabled languages, content types slugs, installed * plugins, etc. * * You can read this information using `Configure::read()` as follow: * * ```php * Configure::read('QuickApps.<option>'); * ``` * * Or using the `quickapps()` global function: * * ```php * quickapps('<option>'); * ``` * * @return void */ function snapshot() { if (Cache::config('default')) { Cache::clear(false, 'default'); } if (Cache::config('_cake_core_')) { Cache::clear(false, '_cake_core_'); } if (Cache::config('_cake_model_')) { Cache::clear(false, '_cake_model_'); } $versionPath = QUICKAPPS_CORE . 'VERSION.txt'; $snapshot = ['version' => null, 'content_types' => [], 'plugins' => [], 'options' => [], 'languages' => [], 'aspects' => []]; if (is_readable($versionPath)) { $versionFile = file($versionPath); $snapshot['version'] = trim(array_pop($versionFile)); } else { die(sprintf('Missing file: %s', $versionPath)); } if (ConnectionManager::config('default')) { if (!TableRegistry::exists('SnapshotPlugins')) { $PluginTable = TableRegistry::get('SnapshotPlugins', ['table' => 'plugins']); } else { $PluginTable = TableRegistry::get('SnapshotPlugins'); } if (!TableRegistry::exists('SnapshotContentTypes')) { $ContentTypesTable = TableRegistry::get('SnapshotContentTypes', ['table' => 'content_types']); } else { $ContentTypesTable = TableRegistry::get('SnapshotContentTypes'); } if (!TableRegistry::exists('SnapshotLanguages')) { $LanguagesTable = TableRegistry::get('SnapshotLanguages', ['table' => 'languages']); } else { $LanguagesTable = TableRegistry::get('SnapshotLanguages'); } if (!TableRegistry::exists('SnapshotOptions')) { $OptionsTable = TableRegistry::get('SnapshotOptions', ['table' => 'options']); } else { $OptionsTable = TableRegistry::get('SnapshotOptions'); } $PluginTable->schema(['value' => 'serialized']); $OptionsTable->schema(['value' => 'serialized']); $plugins = $PluginTable->find()->select(['name', 'package', 'status'])->order(['ordering' => 'ASC', 'name' => 'ASC'])->all(); $contentTypes = $ContentTypesTable->find()->select(['slug'])->all(); $languages = $LanguagesTable->find()->where(['status' => 1])->order(['ordering' => 'ASC'])->all(); $options = $OptionsTable->find()->select(['name', 'value'])->where(['autoload' => 1])->all(); foreach ($contentTypes as $contentType) { $snapshot['content_types'][] = $contentType->slug; } foreach ($options as $option) { $snapshot['options'][$option->name] = $option->value; } foreach ($languages as $language) { list($languageCode, $countryCode) = localeSplit($language->code); $snapshot['languages'][$language->code] = ['name' => $language->name, 'locale' => $language->code, 'code' => $languageCode, 'country' => $countryCode, 'direction' => $language->direction, 'icon' => $language->icon]; } } else { $plugins = []; foreach (Plugin::scan() as $plugin => $path) { $plugins[] = new Entity(['name' => $plugin, 'status' => true, 'package' => 'quickapps-plugins']); } } $folder = new Folder(QUICKAPPS_CORE . 'src/Aspect/'); foreach ($folder->read(false, false, true)[1] as $classFile) { $className = basename(preg_replace('/\\.php$/', '', $classFile)); if (!in_array($className, ['AppAspect', 'Aspect'])) { $snapshot['aspects'][] = "CMS\\Aspect\\{$className}"; } } foreach ($plugins as $plugin) { $pluginPath = false; if (isset(Plugin::scan()[$plugin->name])) { $pluginPath = Plugin::scan()[$plugin->name]; } if ($pluginPath === false) { Debugger::log(sprintf('Plugin "%s" was found in DB but QuickAppsCMS was unable to locate its root directory.', $plugin->name)); continue; } if (!Plugin::validateJson("{$pluginPath}/composer.json")) { Debugger::log(sprintf('Plugin "%s" has a corrupt "composer.json" file (%s).', $plugin->name, "{$pluginPath}/composer.json")); continue; } $aspectsPath = "{$pluginPath}/src/Aspect/"; $eventsPath = "{$pluginPath}/src/Event/"; $fieldsPath = "{$pluginPath}/src/Field/"; $helpFiles = glob($pluginPath . '/src/Template/Element/Help/help*.ctp'); $isTheme = str_ends_with($plugin->name, 'Theme'); $status = (bool) $plugin->status; $humanName = ''; $aspects = []; $eventListeners = []; $fields = []; $subspaces = [$aspectsPath => 'Aspect', $eventsPath => 'Event', $fieldsPath => 'Field']; $varnames = [$aspectsPath => 'aspects', $eventsPath => 'eventListeners', $fieldsPath => 'fields']; foreach ([$aspectsPath, $eventsPath, $fieldsPath] as $path) { if (is_dir($path)) { $Folder = new Folder($path); foreach ($Folder->read(false, false, true)[1] as $classFile) { $className = basename(preg_replace('/\\.php$/', '', $classFile)); $subspace = $subspaces[$path]; $varname = $varnames[$path]; $namespace = "{$plugin->name}\\{$subspace}\\"; ${$varname}[] = $namespace . $className; } } } if (is_readable("{$pluginPath}composer.json")) { $json = (array) json_decode(file_get_contents("{$pluginPath}composer.json"), true); if (!empty($json['extra']['human-name'])) { $humanName = $json['extra']['human-name']; } } if (empty($humanName)) { $humanName = (string) Inflector::humanize((string) Inflector::underscore($plugin->name)); if ($isTheme) { $humanName = trim(str_replace_last('Theme', '', $humanName)); } } $snapshot['plugins'][$plugin->name] = ['name' => $plugin->name, 'humanName' => $humanName, 'package' => $plugin->package, 'isTheme' => $isTheme, 'hasHelp' => !empty($helpFiles), 'hasSettings' => is_readable($pluginPath . '/src/Template/Element/settings.ctp'), 'aspects' => $aspects, 'eventListeners' => $eventListeners, 'fields' => $fields, 'status' => $status, 'path' => $pluginPath]; if ($status) { $snapshot['aspects'] = array_merge($snapshot['aspects'], $aspects); } } Configure::write('QuickApps', $snapshot); if (!Configure::dump('snapshot', 'QuickApps', ['QuickApps'])) { die('QuickAppsCMS was unable to create a snapshot file, check that PHP have permission to write to the "/tmp" directory.'); } }