public function outputArray(array $data, $singular_object_name = 'entity', $plural_object_name = 'entities') { $app = App::i(); $hook_data = ['data' => $data, 'singular_object_name' => $singular_object_name, 'plural_object_name' => $plural_object_name]; $app->applyHookBoundTo($this, "api.response({$this->hookClassName}).array({$plural_object_name}):before", $hook_data); $app->contentType($this->contentType); ob_start(); $this->_outputArray($data, $singular_object_name, $plural_object_name); $output = ob_get_clean(); $hook_data['output'] = $output; $app->applyHookBoundTo($this, "api.response({$this->hookClassName}).array({$plural_object_name}):after", $hook_data); echo $output; $app->stop(); }
/** * Returns the full path to the file. * * @param \MapasCulturais\Entities\File $file The file to get the path * @param bool $relative Returns the relative path? * * @hook **storage.path ($file, &$path)** * @hook **storage.path({$owner_entity}) ($file, &$path)** * @hook **storage.path({$owner_entity}:{$file_group}) ($file, &$path)** */ public function getPath(\MapasCulturais\Entities\File $file, $relative = false) { $app = App::i(); $owner = $file->getOwner(); $result = $this->_getPath($file, $relative); $app->applyHookBoundTo($this, 'storage.path', ['file' => $file, 'path' => &$result]); if ($owner) { $app->applyHookBoundTo($this, 'storage.path(' . $owner->getHookClassPath() . ':' . $file->group . ')', ['file' => $file, 'path' => &$result]); } return $result; }
/** @ORM\PostUpdate */ public function _postUpdate($args = null) { $_hook_class = $this->getHookClassPath($this->objectType); App::i()->applyHookBoundTo($this, 'entity(' . $_hook_class . ').meta(' . $this->key . ').update:after', $args); }
function GET_single() { App::i()->pass(); }
<?php namespace MapasCulturais; $app = App::i(); $em = $app->em; $conn = $em->getConnection(); return array('alter table space add column public' => function () use($conn) { $conn->executeQuery('ALTER TABLE space ADD COLUMN public BOOLEAN NOT NULL DEFAULT false;'); }, 'alter table agent add column parent_id' => function () use($conn) { $conn->executeQuery('ALTER TABLE agent ADD COLUMN parent_id INTEGER;'); $conn->executeQuery('ALTER TABLE ONLY agent ADD CONSTRAINT agent_agent_fk FOREIGN KEY (parent_id) REFERENCES agent(id);'); }, 'alter occurrence fk' => function () use($conn) { $conn->executeQuery("\n ALTER TABLE public.event_occurrence_cancellation\n DROP CONSTRAINT event_occurrence_fk,\n ADD CONSTRAINT event_occurrence_fk\n FOREIGN KEY (event_occurrence_id)\n REFERENCES event_occurrence(id)\n ON DELETE CASCADE"); $conn->executeQuery("\n ALTER TABLE public.event_occurrence_recurrence\n DROP CONSTRAINT event_occurrence_fk,\n ADD CONSTRAINT event_occurrence_fk\n FOREIGN KEY (event_occurrence_id)\n REFERENCES event_occurrence(id)\n ON DELETE CASCADE"); }, 'alter tables to change CHAR to VARCHAR' => function () use($conn) { $conn->executeQuery('ALTER TABLE ONLY agent_meta ALTER COLUMN key TYPE character varying(32);'); $conn->executeQuery('ALTER TABLE ONLY event_meta ALTER COLUMN key TYPE character varying(32);'); $conn->executeQuery('ALTER TABLE ONLY space_meta ALTER COLUMN key TYPE character varying(32);'); $conn->executeQuery('ALTER TABLE ONLY project_meta ALTER COLUMN key TYPE character varying(32);'); $conn->executeQuery('ALTER TABLE ONLY metadata ALTER COLUMN key TYPE character varying(32);'); $conn->executeQuery('ALTER TABLE ONLY file ALTER COLUMN grp TYPE character varying(32);'); }, 'change owner of verified spaces of type Biblioteca Publica to agent SMB (id 592)' => function () use($app) { $smb = $app->repo('Agent')->find(592); $spaces = $app->controller('space')->apiQuery(['@select' => 'id,name,singleUrl', 'owner' => 'IN(@Agent:425)', 'type' => 'EQ(20)']); foreach ($spaces as $i => $space) { echo $i + 1 . ' - ' . $space['name'] . "... "; $b = $app->repo('Space')->find($space['id']); $b->owner = $smb; $b->save(true); echo "OK\n";
list($auid, $old_email, $new_email) = $e; $sql = "UPDATE usr SET email='{$new_email}' WHERE auth_uid = '{$auid}' AND email = '{$old_email}'\n"; echo $sql; $conn->executeQuery($sql); } $users = explode("\n", $data); foreach ($users as $u) { if (!$u) { continue; } $d = explode("\t", $u); list($username, $email, $openid) = $d; if (count($d) != 3) { var_dump($d); } $auid = App::i()->config['auth.config']['login_url'] . str_replace('/openid/', '', $openid) . '/'; $sql = "UPDATE usr SET auth_uid = '{$auid}' WHERE email = '{$email}'\n"; echo $sql; $conn->executeQuery($sql); } return true; }, 'replace "relacioanr" in notification messages asd' => function () use($conn) { $count = $conn->fetchAssoc("SELECT count(*) AS total FROM notification WHERE message LIKE '%relacioanr%'"); if ($count['total'] > 0) { echo 'Atualizando ' . $count['total'] . ' notificações com o erro de grafia "relacioanr"' . "\n"; $sql = "UPDATE notification SET message = replace(message, 'relacioanr', 'relacionar') WHERE message LIKE '%relacioanr%'"; echo $sql; $conn->executeQuery($sql); } return true; }, 'fix select values' => function () use($conn) {
public function createUrl($controller_id, $action_name = '', array $args = array()) { if ($action_name == '') { $action_name = $this->config['default_action_name']; } ksort($args); $route = ''; if ($args && in_array(array($controller_id, $action_name, $args), $this->config['shortcuts'])) { $route = array_search(array($controller_id, $action_name, $args), $this->config['shortcuts']) . '/'; $args = array(); } elseif (in_array(array($controller_id, $action_name), $this->config['shortcuts'])) { $route = array_search(array($controller_id, $action_name), $this->config['shortcuts']) . '/'; } else { if (in_array($controller_id, $this->config['controllers'])) { $route = array_search($controller_id, $this->config['controllers']) . '/'; } else { $route = $controller_id . '/'; } if ($action_name != $this->config['default_action_name']) { if (in_array($action_name, $this->config['actions'])) { $route .= array_search($action_name, $this->config['actions']) . '/'; } else { $route .= $action_name . '/'; } } } foreach ($args as $key => $val) { if (is_numeric($key)) { $route .= $val . '/'; } else { $route .= $key . ':' . $val . '/'; } } return App::i()->baseUrl . $route; }
/** * Verify that there is no other metadata with the same value and key for the same entity class. * * @param \MapasCulturais\Entity $owner the owner of the metadata value * @param type $value the value to check. * * @return bool true if there is no metadata with the same value, false otherwise. */ protected function validateUniqueValue(\MapasCulturais\Entity $owner, $value) { $app = App::i(); $owner_class = $owner->className; if (class_exists($owner_class . 'Meta')) { $q = $app->em->createQuery("SELECT COUNT(m) FROM {$owner_class}Meta m WHERE m.key = :key AND m.value = :value AND m.owner != :owner"); $q->setParameters(['key' => $this->key, 'value' => $value, 'owner' => $owner]); } else { $q = $app->em->createQuery("SELECT COUNT(m) FROM \\MapasCulturais\\Entities\\Metadata m WHERE m.key = :key AND m.value = :value AND m.ownerType :ownerType AND m.ownerId != :ownerId"); $q->setParameters(['key' => $this->key, 'value' => $value, 'ownerType' => $owner_class, 'ownerId' => $owner->id]); } return !$q->getSingleScalarResult(); }
<?php namespace MapasCulturais; define('BASE_PATH', realpath(__DIR__ . '/../../') . '/'); define('PROTECTED_PATH', realpath(__DIR__ . '/../') . '/'); define('APPLICATION_PATH', realpath(__DIR__) . '/'); define('THEMES_PATH', APPLICATION_PATH . 'themes/'); define('ACTIVE_THEME_PATH', THEMES_PATH . 'active/'); define('PLUGINS_PATH', APPLICATION_PATH . '/plugins/'); define('AUTOLOAD_TTL', 60 * 5); require_once __DIR__ . "/../vendor/autoload.php"; $config = (include __DIR__ . '/conf/config.php'); // create the App instance $app = App::i()->init($config);
function publishAsset($asset_filename, $destination = null) { $app = App::i(); if (preg_match('#^(\\/\\/|https?)#', $asset_filename)) { return $asset_filename; } $asset_filename = $app->view->getAssetFilename($asset_filename); if (!$asset_filename) { return ''; } $info = pathinfo($asset_filename); $extension = strtolower($info['extension']); if (!$destination) { $destination_file = $this->_getPublishedAssetFilename($asset_filename); if (in_array($extension, ['jpg', 'png', 'gif', 'ico'])) { $destination = "img/{$destination_file}"; } else { $destination = "{$extension}/{$destination_file}"; } } $cache_id = __METHOD__ . '::' . $asset_filename . '->' . $destination; if ($app->config['app.useAssetsUrlCache'] && $app->cache->contains($cache_id)) { return $app->cache->fetch($cache_id); } else { $asset_url = $this->_publishAsset($asset_filename, $destination); if ($app->config['app.useAssetsUrlCache']) { $app->cache->save($cache_id, $asset_url); } return $asset_url; } }
protected final function _setAuthenticatedUser(Entities\User $user = null) { App::i()->applyHookBoundTo($this, 'auth.login', [$user]); $this->_authenticatedUser = $user; }
function POST_single() { App::i()->pass(); }