Exemplo n.º 1
0
 public function postModule(PostModuleEvent $event)
 {
     $pageModuleWrapper = $event->getModuleWrapper();
     $queryCount = $event->getExtra('module_profiler.query_count');
     $time = microtime(true) - $event->getExtra('module_profiler.time');
     $userTime = Helper::getCpuTime('u') - $event->getExtra('module_profiler.user_time');
     $systemTime = Helper::getCpuTime('s') - $event->getExtra('module_profiler.system_time');
     $memoryUsage = memory_get_usage(true) - $event->getExtra('module_profiler.memory_usage');
     $sqlQueries = $queryCount !== null ? Propel::getQueryCount() - $queryCount : null;
     if ($userTime + $systemTime > $this->cpuLimit || $time > $this->timeLimit) {
         $this->logger->warning('Module generation time exceeded limit');
     }
     if ($memoryUsage > $this->memoryLimit) {
         $this->logger->warning('Module memory usage exceeded limit');
     }
     if ($sqlQueries > $this->sqlLimit) {
         $this->logger->warning('Module sql query count exceeded limit');
     }
     // add module debug info
     $this->moduleDebugInfo[] = array($pageModuleWrapper->getName(), $pageModuleWrapper->getClassName(), $pageModuleWrapper->getTemplate(), $pageModuleWrapper->getTarget(), (bool) $event->getExtra('module_cacher.cached'), round($time * 1000.0), round(($userTime + $systemTime) * 1000.0), Helper::humanReadableBytes($memoryUsage), Helper::humanReadableBytes(memory_get_peak_usage(true)), $sqlQueries !== null ? $sqlQueries : 'n/a');
     // Remove values to prevent caching
     $extras = $event->getExtras();
     unset($extras['module_profiler.time']);
     unset($extras['module_profiler.query_count']);
     unset($extras['module_profiler.user_time']);
     unset($extras['module_profiler.system_time']);
     unset($extras['module_profiler.memory_usage']);
     $event->setExtras($extras);
 }
Exemplo n.º 2
0
 /**
  * Get file details.
  *
  * @param array $selected
  * @return array
  */
 public function getFileInfo($selected)
 {
     if (count($selected) == 1) {
         try {
             $path = $selected[0];
             $physical = self::virtualToPhysical($path);
             $public = self::physicalToPublic($physical);
             if (!is_file($physical)) {
                 return null;
             }
             $owner = fileowner($physical);
             if (function_exists('posix_getpwuid')) {
                 $owner = posix_getpwuid($owner);
                 $owner = '<span title="' . $owner['uid'] . '">' . htmlspecialchars($owner['name']) . '</span>';
             }
             $group = filegroup($physical);
             if (function_exists('posix_getgrgid')) {
                 $group = posix_getgrgid($group);
                 $group = '<span title="' . $group['gid'] . '">' . htmlspecialchars($group['name']) . '</span>';
             }
             $fi = array('Name' => '<h2>' . basename($physical) . '</h2>', 'Preview' => '', 'Size' => '<strong>Size: </strong>' . Helper::humanReadableBytes(filesize($physical)), 'Writable' => '<strong>Writable: </strong>' . (self::isWritable($physical) ? 'Yes' : 'No'), 'Permissions' => '<strong>Permissions: </strong>' . PathHelper::getFilePermissions($physical), 'Owner' => '<strong>Owner: </strong>' . $owner . ' / ' . $group);
             switch (strtolower(pathinfo($physical, PATHINFO_EXTENSION))) {
                 case 'jpg':
                 case 'gif':
                 case 'png':
                 case 'bmp':
                     $image = getimagesize($physical);
                     $fi['Preview'] = '<img src="' . $public . '?' . filemtime($physical) . '" alt="" class="preview" />';
                     if ($image[0] > 240 || $image[1] > 240) {
                         $fi['Preview'] = '<a href="' . $public . '?' . filemtime($physical) . '" target="_blank" class="fullscreen-preview" title="Click to toggle fullscreen">' . $fi['Preview'] . '</a>';
                     }
                     $fi['Dimensions'] = '<strong>Dimension: </strong>' . $image[0] . 'x' . $image[1];
                     if (self::isPhysicalWritable($physical)) {
                         $fi['Actions'] = '<a href="' . url('', array('module', 'view' => 'PixlrEdit', 'image' => $public)) . '" class="dialog" onclick="$(this).data(\'dialog\').width = $(window).width() - 20; $(this).data(\'dialog\').height = $(window).height() - 20;" data-dialog=\'{"width":"90%","height":600,"resizable":false,"draggable":false}\'>Edit with Pixlr</a>';
                     }
                     break;
                 case 'ogg':
                 case 'ogv':
                 case 'mp4':
                 case 'webm':
                     $fi['Preview'] = '<video src="' . $public . '" class="preview" controls />';
                     break;
                 case 'mp3':
                 case 'oga':
                 case 'wav':
                     $fi['Preview'] = '<audio src="' . $public . '" class="preview" controls />';
                     break;
                 case 'swf':
                     $size = getimagesize($physical);
                     $flash = Flash::embed(Flash::SWFOBJECT_STATIC, $public, $size[0], $size[1], '9.0.0', array());
                     $fi['Preview'] = $flash['html'];
                     break;
             }
             return $fi;
         } catch (Exception $e) {
             $this->app->logger->error($e->getMessage());
         }
     } else {
         $totalSize = 0;
         foreach ($selected as $s) {
             $physical = self::virtualToPhysical($s);
             $totalSize += filesize($physical);
         }
         return array('Name' => '<h2>' . count($selected) . ' files</h2>', 'Size' => '<strong>Size: </strong>' . Helper::humanReadableBytes($totalSize));
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $startTime = microtime(true);
     $this->logger->debug(($type === HttpKernelInterface::MASTER_REQUEST ? 'Master-Request: ' : 'Sub-Request') . $request->getMethod() . ' ' . $request->getRequestUri());
     $previous = isset($this->request) ? $this->request : null;
     $this->request = $request;
     $response = $this->kernel->handle($request, $type, $catch);
     $this->request = $previous;
     if ($this['developmentMode']) {
         $queryCount = Util\Propel::getQueryCount();
         $this->logger->debug("Response completed", array('time' => microtime(true) - $startTime, 'mem' => Helper::humanReadableBytes(memory_get_peak_usage()), 'sql' => $queryCount !== null ? $queryCount : 'n/a'));
     }
     return $response;
 }
Exemplo n.º 4
0
 /**
  * Restore database.
  */
 public function showRestore()
 {
     $this->showMainMenu();
     $tables = array();
     $selectedTables = array();
     $disabledTables = array();
     foreach (Propel::getModels() as $package => $classes) {
         $tables[$package] = array();
         foreach ($classes as $table) {
             $tables[$package][$table] = $table;
             if (method_exists($table, 'save')) {
                 $selectedTables[] = $table;
             } else {
                 $disabledTables[] = $table;
             }
         }
     }
     $files = array('' => '-- Select file --', 'upload' => '[ Upload from computer ]', 'remote' => '[ From remote server ]');
     $path = Curry_Backend_DatabaseHelper::createBackupName('*.txt');
     foreach (array_reverse(glob($path)) as $file) {
         $files[$file] = basename($file) . ' (' . Helper::humanReadableBytes(filesize($file)) . ')';
     }
     $form = new Curry_Form(array('action' => url('', array("module", "view", "page_id")), 'method' => 'post', 'enctype' => 'multipart/form-data', 'elements' => array('tables' => array('multiselect', array('label' => 'Tables', 'multiOptions' => $tables, 'value' => $selectedTables, 'disable' => $disabledTables, 'size' => 15)), 'file' => array('select', array('label' => 'From file', 'multiOptions' => $files, 'class' => 'trigger-change', 'onchange' => "\$('#uploadfile-label').next().andSelf()[this.value == 'upload'?'show':'hide']();" . "\$('#remote-label').next().andSelf()[this.value == 'remote'?'show':'hide']();")), 'uploadfile' => array('file', array('label' => 'Upload file', 'valueDisabled' => true)), 'remote' => array('text', array('label' => 'Remote')), 'max_execution_time' => array('text', array('label' => 'Max execution time', 'value' => '', 'description' => 'Input time in seconds to allow interruption if the time taken to restore would exceed the maximum execution time.')))));
     $form->addElement('submit', 'Go');
     if (isPost() && $form->isValid($_POST)) {
         if ($form->file->getValue() == 'upload') {
             if (!$form->uploadfile->isUploaded()) {
                 throw new Exception('No file was uploaded.');
             }
             $fileinfo = $form->uploadfile->getFileInfo();
             Curry_Backend_DatabaseHelper::restoreFromFile($fileinfo['uploadfile']['tmp_name'], $form->tables->getValue(), 0, 0, $this);
         } else {
             if ($form->file->getValue() == 'remote') {
                 if (!$form->remote->getValue()) {
                     throw new Exception('No remote URL set');
                 }
                 $url = url($form->remote->getValue());
                 $post = array('login_username' => $url->getUser(), 'login_password' => $url->getPassword(), 'tables' => '*', 'name' => 'db.txt', 'type' => 'local');
                 $url->setUser(null)->setPassword(null)->setPath('/admin.php')->add(array('module' => 'Curry_Backend_Database', 'view' => 'Backup'));
                 $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'content' => http_build_query($post))));
                 $fp = fopen($url, 'r', false, $context);
                 Curry_Backend_DatabaseHelper::restoreFromFile($fp, $form->tables->getValue(), 0, 0, $this);
                 fclose($fp);
             } else {
                 if ($form->file->getValue()) {
                     Curry_Backend_DatabaseHelper::restoreFromFile($form->file->getValue(), $form->tables->getValue(), (int) $form->max_execution_time->getValue(), 0, $this);
                 }
             }
         }
     }
     $this->addMainContent($form);
 }