Exemplo n.º 1
0
 public function uploadAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $this->view->layout()->disableLayout(true);
     $adapter = new Zend_ProgressBar_Adapter_JsPush(array('updateMethodName' => 'Zend_ProgressBar_Update', 'finishMethodName' => 'Zend_ProgressBar_Finish'));
     $progressBar = new Zend_ProgressBar($adapter, 0, 100);
     for ($i = 1; $i <= 100; $i++) {
         if ($i < 20) {
             $text = 'Just beginning';
         } else {
             if ($i < 50) {
                 $text = 'A bit done';
             } else {
                 if ($i < 80) {
                     $text = 'Getting closer';
                 } else {
                     $text = 'Nearly done';
                 }
             }
         }
         $progressBar->update($i, $text);
         usleep(100000);
     }
     $progressBar->finish();
 }
Exemplo n.º 2
0
 public function uploadAction()
 {
     $adapter = new Zend_ProgressBar_Adapter_JsPush(array('updateMethodName' => 'Zend_ProgressBar_Update', 'finishMethodName' => 'Zend_ProgressBar_Finish'));
     $progressBar = new Zend_ProgressBar($adapter, 0, 100);
     for ($i = 1; $i <= 100; $i++) {
         if ($i < 20) {
             $text = 'Just beginning';
         } else {
             if ($i < 50) {
                 $text = 'A bit done';
             } else {
                 if ($i < 80) {
                     $text = 'Getting closer';
                 } else {
                     $text = 'Nearly done';
                 }
             }
         }
         $progressBar->update($i, $text);
         usleep(100000);
     }
     $progressBar->finish();
 }
Exemplo n.º 3
0
 public function executeUpdates($options = array())
 {
     $doneNames = array();
     $this->_executeUpdatesAction('preUpdate');
     $this->_executeUpdatesAction('update');
     if ($this->_progressBar) {
         $this->_progressBar->finish();
     }
     $this->_executeUpdatesAction('postUpdate');
     if (!$this->_skipClearCache) {
         if ($this->_verbose) {
             echo "\n";
         }
         Kwf_Util_ClearCache::getInstance()->clearCache(array('types' => 'all', 'excludeTypes' => $this->_excludeClearCacheTypes, 'output' => $this->_verbose, 'refresh' => isset($options['refreshCache']) ? $options['refreshCache'] : true));
         if ($this->_verbose) {
             echo "\n";
         }
     }
     $this->_executeUpdatesAction('postClearCache');
     foreach ($this->_updates as $k => $u) {
         $doneNames[] = $u->getUniqueName();
     }
     return $doneNames;
 }
Exemplo n.º 4
0
 /**
  * Returns the actual progress of file up-/downloads
  *
  * @param  string $id The upload to get the progress for
  * @return array|null
  */
 public static function getProgress($id = null)
 {
     if (!function_exists('apc_fetch') and !function_exists('uploadprogress_get_info')) {
         // require_once 'Zend/File/Transfer/Exception.php';
         throw new Zend_File_Transfer_Exception('Neither APC nor uploadprogress extension installed');
     }
     $session = 'Zend_File_Transfer_Adapter_Http_ProgressBar';
     $status = array('total' => 0, 'current' => 0, 'rate' => 0, 'message' => '', 'done' => false);
     if (is_array($id)) {
         if (isset($id['progress'])) {
             $adapter = $id['progress'];
         }
         if (isset($id['session'])) {
             $session = $id['session'];
         }
         if (isset($id['id'])) {
             $id = $id['id'];
         } else {
             unset($id);
         }
     }
     if (!empty($id) && ($id instanceof Zend_ProgressBar_Adapter || $id instanceof Zend_ProgressBar)) {
         $adapter = $id;
         unset($id);
     }
     if (empty($id)) {
         if (!isset($_GET['progress_key'])) {
             $status['message'] = 'No upload in progress';
             $status['done'] = true;
         } else {
             $id = $_GET['progress_key'];
         }
     }
     if (!empty($id)) {
         if (self::isApcAvailable()) {
             $call = call_user_func(self::$_callbackApc, ini_get('apc.rfc1867_prefix') . $id);
             if (is_array($call)) {
                 $status = $call + $status;
             }
         } else {
             if (self::isUploadProgressAvailable()) {
                 $call = call_user_func(self::$_callbackUploadProgress, $id);
                 if (is_array($call)) {
                     $status = $call + $status;
                     $status['total'] = $status['bytes_total'];
                     $status['current'] = $status['bytes_uploaded'];
                     $status['rate'] = $status['speed_average'];
                     if ($status['total'] == $status['current']) {
                         $status['done'] = true;
                     }
                 }
             }
         }
         if (!is_array($call)) {
             $status['done'] = true;
             $status['message'] = 'Failure while retrieving the upload progress';
         } else {
             if (!empty($status['cancel_upload'])) {
                 $status['done'] = true;
                 $status['message'] = 'The upload has been canceled';
             } else {
                 $status['message'] = self::_toByteString($status['current']) . " - " . self::_toByteString($status['total']);
             }
         }
         $status['id'] = $id;
     }
     if (isset($adapter) && isset($status['id'])) {
         if ($adapter instanceof Zend_ProgressBar_Adapter) {
             // require_once 'Zend/ProgressBar.php';
             $adapter = new Zend_ProgressBar($adapter, 0, $status['total'], $session);
         }
         if (!$adapter instanceof Zend_ProgressBar) {
             // require_once 'Zend/File/Transfer/Exception.php';
             throw new Zend_File_Transfer_Exception('Unknown Adapter given');
         }
         if ($status['done']) {
             $adapter->finish();
         } else {
             $adapter->update($status['current'], $status['message']);
         }
         $status['progress'] = $adapter;
     }
     return $status;
 }
$processesCheck = "ps x | grep \"{$child}\" | grep -v grep";
$i = 0;
for (; $batches; $batches--) {
    $output = '';
    if ($threadCount == 1) {
        exec($child . " {$i} {$batchSize} >> " . dirname(__FILE__) . "/url_migration.log 2>&1", $output, $status);
    } else {
        waitForChildren($processesCheck, $threadCount);
        exec($child . " {$i} {$batchSize} >> " . dirname(__FILE__) . "/url_migration.log 2>&1 &", $output, $status);
    }
    $categoriesProgressBar->update(++$i, '');
}
if ($threadCount != 1) {
    waitForChildren($processesCheck, 1);
}
$categoriesProgressBar->finish();
$cnxConfig = Mage::getConfig()->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
$connection = $migration->getResource()->createConnection('fresh_connection', (string) $cnxConfig->type, $cnxConfig);
$connection->dropTable($tableProducts->getName());
$connection->dropTable($tableCategories->getName());
exit(0);
function waitForChildren($command, $count)
{
    $out = array();
    exec($command, $out);
    $processCount = count($out);
    while ($processCount >= $count) {
        sleep(4);
        $out = array();
        exec($command, $out);
        $processCount = count($out);
Exemplo n.º 6
0
            $text = 'Just beginning';
        } else {
            if ($i < 50) {
                $text = 'A bit done';
            } else {
                if ($i < 80) {
                    $text = 'Getting closer';
                } else {
                    $text = 'Nearly done';
                }
            }
        }
        $progressBar->update($i, $text);
        usleep(100000);
    }
    $progressBar->finish();
    die;
}
?>
<html>
<head>
    <title>Zend_ProgressBar Javascript Push Demo and Test</title>
    <style type="text/css">
        iframe {
            position: absolute;
            left: -100px;
            top: -100px;

            width: 10px;
            height: 10px;
            overflow: hidden;
Exemplo n.º 7
0
 protected function _build($options)
 {
     if (!file_exists('build/assets')) {
         mkdir('build/assets');
     }
     Kwf_Assets_BuildCache::getInstance()->building = true;
     Kwf_Assets_BuildCache::getInstance()->clean();
     Kwf_Assets_BuildCache::getInstance()->save(time(), 'assetsVersion');
     $langs = $this->_getAllLanguages();
     $packages = $this->_getAllPackages();
     $exts = array('js', 'defer.js', 'css', 'printcss');
     echo "\ncalculating dependencies...\n";
     $steps = count($packages) * count($exts);
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     $countDependencies = 0;
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         foreach ($exts as $extension) {
             $progress->next(1, "{$depName} {$extension}");
             $countDependencies += count($p->getFilteredUniqueDependencies(self::$_mimeTypeByExtension[$extension]));
             $cacheId = $p->getMaxMTimeCacheId(self::$_mimeTypeByExtension[$extension]);
             if (!$cacheId) {
                 throw new Kwf_Exception("Didn't get cacheId for " . get_class($p));
             }
             $maxMTime = $p->getMaxMTime(self::$_mimeTypeByExtension[$extension]);
             Kwf_Assets_BuildCache::getInstance()->save($maxMTime, $cacheId);
             //save generated caches for clear-cache-watcher
             $fileName = 'build/assets/package-max-mtime-' . $extension;
             if (!file_exists($fileName) || strpos(file_get_contents($fileName), $cacheId . "\n") === false) {
                 file_put_contents($fileName, $cacheId . "\n", FILE_APPEND);
             }
         }
     }
     $progress->finish();
     echo "compiling assets...\n";
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $countDependencies);
     foreach ($packages as $p) {
         foreach ($exts as $extension) {
             foreach ($p->getFilteredUniqueDependencies(self::$_mimeTypeByExtension[$extension]) as $dep) {
                 $progress->next(1, "{$dep}");
                 $dep->warmupCaches();
             }
         }
     }
     $progress->finish();
     echo "generating packages...\n";
     $steps = count($packages) * count($langs) * count($exts) * 4;
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         foreach ($langs as $language) {
             foreach ($exts as $extension) {
                 $packageContents = $p->getPackageContents(self::$_mimeTypeByExtension[$extension], $language);
                 $maxMTime = $p->getMaxMTime(self::$_mimeTypeByExtension[$extension]);
                 $progress->next(1, "{$depName} {$extension} {$language}");
                 $progress->next(1, "{$depName} {$extension} {$language} source");
                 $this->_buildPackageContents($packageContents, $maxMTime, $p, $extension, $language);
                 $progress->next(1, "{$depName} {$extension} {$language} map");
                 $this->_buildPackageSourceMap($packageContents, $maxMTime, $p, $extension, $language);
                 $progress->next(1, "{$depName} {$extension} {$language} url");
                 $urls = $p->getPackageUrls(self::$_mimeTypeByExtension[$extension], $language);
                 if (Kwf_Setup::getBaseUrl()) {
                     foreach ($urls as $k => $i) {
                         $urls[$k] = substr($i, strlen(Kwf_Setup::getBaseUrl()));
                     }
                 }
                 $cacheId = $p->getPackageUrlsCacheId(self::$_mimeTypeByExtension[$extension], $language);
                 Kwf_Assets_BuildCache::getInstance()->save($urls, $cacheId);
             }
         }
     }
     Kwf_Assets_Cache::getInstance()->clean();
     Kwf_Assets_BuildCache::getInstance()->building = false;
     $exts = array('js', 'defer.js', 'css');
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         $language = $langs[0];
         foreach ($exts as $extension) {
             $cacheId = Kwf_Assets_Dispatcher::getCacheIdByPackage($p, $extension, $language);
             $cacheContents = Kwf_Assets_BuildCache::getInstance()->load($cacheId);
             echo "{$depName} ";
             $h = new Kwf_View_Helper_FileSize();
             echo "{$extension} size: " . $h->fileSize(strlen(gzencode($cacheContents['contents'], 9, FORCE_GZIP)));
             echo "\n";
         }
     }
     $d = Kwf_Assets_Package_Default::getDefaultProviderList()->findDependency('Frontend');
     foreach ($d->getFilteredUniqueDependencies('text/javascript') as $i) {
         if ($i instanceof Kwf_Assets_Dependency_File && $i->getType() == 'ext2') {
             echo "\n[WARNING] Frontend text/javascript contains ext2\n";
             echo "To improve frontend performance all ext2 dependencies should be moved to defer\n\n";
             break;
         }
     }
 }
Exemplo n.º 8
0
 protected function _build($options)
 {
     if (!file_exists('build/assets')) {
         mkdir('build/assets');
     }
     Kwf_Assets_BuildCache::getInstance()->building = true;
     Kwf_Assets_BuildCache::getInstance()->clean();
     Kwf_Assets_BuildCache::getInstance()->save(time(), 'assetsVersion');
     $langs = $this->getAllLanguages();
     $packages = $this->getAllPackages();
     $exts = array('js', 'defer.js', 'css');
     echo "\ncalculating dependencies...\n";
     $steps = count($packages) * count($exts);
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     $countDependencies = 0;
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         foreach ($exts as $extension) {
             $progress->next(1, "{$depName} {$extension}");
             $p->getFilteredUniqueDependencies(self::$_mimeTypeByExtension[$extension]);
             $cacheId = $p->getMaxMTimeCacheId(self::$_mimeTypeByExtension[$extension]);
             if (!$cacheId) {
                 throw new Kwf_Exception("Didn't get cacheId for " . get_class($p));
             }
             $maxMTime = $p->getMaxMTime(self::$_mimeTypeByExtension[$extension]);
             Kwf_Assets_BuildCache::getInstance()->save($maxMTime, $cacheId);
             //save generated caches for clear-cache-watcher
             $fileName = 'build/assets/package-max-mtime-' . $extension;
             if (!file_exists($fileName) || strpos(file_get_contents($fileName), $cacheId . "\n") === false) {
                 file_put_contents($fileName, $cacheId . "\n", FILE_APPEND);
             }
         }
         $it = new RecursiveIteratorIterator(new Kwf_Assets_Dependency_Iterator_UniqueFilter(new Kwf_Assets_Dependency_Iterator_Recursive($p->getDependency(), Kwf_Assets_Dependency_Abstract::DEPENDENCY_TYPE_ALL)), RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($it as $i) {
             $countDependencies++;
         }
     }
     $progress->finish();
     echo "compiling assets...\n";
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $countDependencies);
     foreach ($packages as $p) {
         $it = new RecursiveIteratorIterator(new Kwf_Assets_Dependency_Iterator_UniqueFilter(new Kwf_Assets_Dependency_Iterator_Recursive($p->getDependency(), Kwf_Assets_Dependency_Abstract::DEPENDENCY_TYPE_ALL)), RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($it as $dep) {
             $progress->next(1, "{$dep}");
             $dep->warmupCaches();
         }
     }
     $progress->finish();
     echo "generating packages...\n";
     $steps = count($packages) * count($langs) * count($exts) * 4;
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         foreach ($langs as $language) {
             foreach ($exts as $extension) {
                 $progress->next(1, "{$depName} {$extension} {$language}");
                 $packageContents = $p->getPackageContents(self::$_mimeTypeByExtension[$extension], $language);
                 $maxMTime = $p->getMaxMTime(self::$_mimeTypeByExtension[$extension]);
                 $progress->next(1, "{$depName} {$extension} {$language} source");
                 $this->_buildPackageContents($packageContents, $maxMTime, $p, $extension, $language);
                 $progress->next(1, "{$depName} {$extension} {$language} map");
                 $this->_buildPackageSourceMap($packageContents, $maxMTime, $p, $extension, $language);
                 $progress->next(1, "{$depName} {$extension} {$language} url");
                 $urls = $p->getPackageUrls(self::$_mimeTypeByExtension[$extension], $language);
                 if (Kwf_Setup::getBaseUrl()) {
                     foreach ($urls as $k => $i) {
                         $urls[$k] = substr($i, strlen(Kwf_Setup::getBaseUrl()));
                     }
                 }
                 $cacheId = $p->getPackageUrlsCacheId(self::$_mimeTypeByExtension[$extension], $language);
                 Kwf_Assets_BuildCache::getInstance()->save($urls, $cacheId);
             }
         }
     }
     Kwf_Assets_Cache::getInstance()->clean();
     Kwf_Assets_BuildCache::getInstance()->building = false;
 }
Exemplo n.º 9
0
 public function deleteViewCache($select, $progressBarAdapter = null)
 {
     $microtime = $this->_getMicrotime();
     $select->whereEquals('deleted', false);
     $model = $this->getModel();
     $log = Kwf_Events_Log::getInstance();
     $cacheIds = array();
     $options = array('columns' => array('component_id', 'renderer', 'type', 'value'));
     $partialIds = array();
     $deleteIds = array();
     $checkIncludeIds = array();
     $rows = $model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select, $options);
     $progress = null;
     if ($progressBarAdapter) {
         $count = count($rows);
         $steps = (int) (count($rows) * 2 / 100 + 3);
         $step = 0;
         $progress = new Zend_ProgressBar($progressBarAdapter, 0, $steps);
     }
     foreach ($rows as $key => $row) {
         if ($progress && $key % 100 == 0) {
             $step += 100;
             $progress->next(1, "viewcache {$step} / {$count}");
         }
         $cacheIds[] = $this->_getCacheId($row['component_id'], $row['renderer'], $row['type'], $row['value']);
         Kwf_Benchmark::countLog('viewcache-delete-' . $row['type']);
         if ($row['type'] != 'fullPage' && !isset($checkIncludeIds[$row['component_id']])) {
             $checkIncludeIds[$row['component_id']] = true;
         }
         if ($log) {
             $log->log("delete view cache {$row['component_id']} {$row['renderer']} {$row['type']} {$row['value']}", Zend_Log::INFO);
         }
         $type = $row['type'];
         $value = $row['value'];
         $cId = $row['component_id'];
         if ($type == 'partial' && $value != '') {
             if (!isset($partialIds[$cId])) {
                 $partialIds[$cId] = array();
             }
             $partialIds[$cId][] = $value;
         } else {
             if ($value == '') {
                 if (!isset($deleteIds[$type])) {
                     $deleteIds[$type] = array();
                 }
                 $deleteIds[$type][] = $cId;
             } else {
                 throw new Kwf_Exception('Should not happen.');
             }
         }
     }
     // Memcache
     $this->_beforeMemcacheDelete($select);
     // For unit testing - DO NOT DELETE!
     if ($progress) {
         $step = 0;
     }
     foreach ($cacheIds as $key => $cacheId) {
         if ($progress && $key % 100 == 0) {
             $step += 100;
             $progress->next(1, "memcache {$step} / {$count}");
         }
         Kwf_Component_Cache_Memory::getInstance()->remove($cacheId, $microtime);
     }
     $this->_afterMemcacheDelete($select);
     // For unit testing - DO NOT DELETE!
     // FullPage
     if ($progress) {
         $progress->next(1, "fullPage");
     }
     $s = new Kwf_Model_Select();
     $s->whereEquals('type', 'fullPage');
     if ($checkIncludeIds) {
         $ids = array_keys($this->_fetchIncludesTree(array_keys($checkIncludeIds)));
         if ($ids) {
             foreach ($ids as &$id) {
                 $id = (string) $id;
             }
             unset($id);
             $s->whereEquals('component_id', $ids);
             if ($log) {
                 foreach ($ids as $id) {
                     $log->log("type=fullPage component_id={$id}", Zend_Log::INFO);
                 }
             }
             $this->deleteViewCache($s);
         }
     }
     // Database
     $this->_beforeDatabaseDelete($select);
     // For unit testing - DO NOT DELETE!
     if ($progress) {
         $progress->next(1, "partialIds");
     }
     foreach ($partialIds as $componentId => $values) {
         $select = $model->select();
         $select->where(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equals('component_id', (string) $componentId), new Kwf_Model_Select_Expr_Equals('type', 'partial'), new Kwf_Model_Select_Expr_Equals('value', $values), new Kwf_Model_Select_Expr_LowerEqual('microtime', $microtime))));
         $model->updateRows(array('deleted' => true), $select);
     }
     if ($progress) {
         $progress->next(1, "deleteIds");
     }
     foreach ($deleteIds as $type => $componentIds) {
         $select = $model->select();
         $select->where(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equals('component_id', $componentIds), new Kwf_Model_Select_Expr_Equals('type', $type), new Kwf_Model_Select_Expr_LowerEqual('microtime', $microtime))));
         $model->updateRows(array('deleted' => true), $select);
     }
     $this->_afterDatabaseDelete($select);
     // For unit testing - DO NOT DELETE!
     if ($progress) {
         $progress->finish();
     }
     file_put_contents('log/clear-view-cache', date('Y-m-d H:i:s') . ' ' . round(microtime(true) - Kwf_Benchmark::$startTime, 2) . 's; ' . Kwf_Events_Dispatcher::$eventsCount . ' events; ' . count($deleteIds) . ' view cache entries deleted; ' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "\n", FILE_APPEND);
     return count($cacheIds);
 }
Exemplo n.º 10
0
 /**
  * Action - pdf
  * сreate a PDF document using the mPDF library
  *
  * Access to the action is possible in the following paths:
  * - /admin/tools/pdf
  *
  * @return void
  */
 public function pdfAction()
 {
     $isCommonFont = false;
     $pdfParams = array();
     //---------------------
     // Получим параметры
     $params = $this->getRequest()->getParams();
     $report = $params['name'];
     // Определим параметры для конвертации HTML в PDF
     switch ($report) {
         case 'phpinfo':
             // Установим параметры для отчета
             $html = Default_Plugin_SysBox::getPHPInfo();
             $pdfParams['pdfReport'] = $report;
             $pdfParams['html'] = $html;
             $pdfParams['isCommonFont'] = true;
             $pdfParams['pathStylesheet'] = 'css/report/phpinfo.css';
             $pdfParams['headerLeftMargin'] = 'Params of PHP';
             $pdfParams['headerCentreMargin'] = Default_Plugin_SysBox::getFullURL_Res('/images/system/settings32x32.png');
             $pdfParams['footerRightMargin'] = Default_Plugin_SysBox::getFullUrl_For_FilePDF($report);
             break;
         case 'zend-progress':
             $adapter = new Zend_ProgressBar_Adapter_JsPush(array('updateMethodName' => 'BSA.Dialogs.Zend_ProgressBar_Update', 'finishMethodName' => 'BSA.Dialogs.Zend_ProgressBar_Finish'));
             $progressBar = new Zend_ProgressBar($adapter, 0, 100);
             for ($i = 1; $i <= 100; $i++) {
                 if ($i < 20) {
                     $text = 'Just beginning';
                 } else {
                     if ($i < 50) {
                         $text = 'A bit done';
                     } else {
                         if ($i < 80) {
                             $text = 'Getting closer';
                         } else {
                             $text = 'Nearly done';
                         }
                     }
                 }
                 $progressBar->update($i, $text);
                 usleep(100000);
             }
             $progressBar->finish();
             die;
             break;
         default:
             break;
     }
     // Создать PDF файл из HTML
     $urlFilePDF = Default_Plugin_SysBox::mpdfGenerator_Html2PDF($pdfParams);
     // Установим свой и предыдущий Breadcrumbs
     $Zend_Auth = Zend_Registry::get("Zend_Auth");
     $lastBreadcrumbs = $Zend_Auth->lastBreadcrumbs;
     $this->_breadcrumbs->addStep($lastBreadcrumbs['title'], $this->getUrl($lastBreadcrumbs['action'], $lastBreadcrumbs['controller'], $lastBreadcrumbs['module']));
     $this->_breadcrumbs->addStep($this->Translate('Отчет в PDF формате'));
     $this->view->urlFilePDF = $urlFilePDF;
 }
Exemplo n.º 11
0
 protected function _build($options)
 {
     if (!file_exists('build/assets')) {
         mkdir('build/assets');
     }
     Kwf_Assets_BuildCache::getInstance()->building = true;
     Kwf_Assets_BuildCache::getInstance()->clean();
     Kwf_Assets_BuildCache::getInstance()->save(time(), 'assetsVersion');
     $langs = $this->getAllLanguages();
     $packages = $this->getAllPackages();
     $exts = array('js', 'defer.js', 'css', 'ie8.css', 'ie8.js');
     $providers = array();
     foreach ($packages as $p) {
         foreach ($p->getProviderList()->getProviders() as $provider) {
             if (!in_array($provider, $providers)) {
                 $providers[] = $provider;
             }
         }
     }
     echo "\ninitializing providers...\n";
     $steps = count($providers);
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(80);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     foreach ($providers as $provider) {
         $progress->next(1, get_class($provider));
         $provider->initialize();
     }
     $progress->finish();
     echo "calculating dependencies...\n";
     $steps = count($packages) * count($exts);
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(80);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     $countDependencies = 0;
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         foreach ($exts as $extension) {
             $progress->next(1, "{$depName} {$extension}");
             $p->getFilteredUniqueDependencies(self::$_mimeTypeByExtension[$extension]);
         }
         $it = new RecursiveIteratorIterator(new Kwf_Assets_Dependency_Iterator_UniqueFilter(new Kwf_Assets_Dependency_Iterator_Recursive($p->getDependency(), Kwf_Assets_Dependency_Abstract::DEPENDENCY_TYPE_ALL)), RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($it as $i) {
             $countDependencies++;
         }
     }
     $progress->finish();
     echo "compiling assets...\n";
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_ETA, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(80);
     $progress = new Zend_ProgressBar($c, 0, $countDependencies);
     foreach ($packages as $p) {
         $it = new RecursiveIteratorIterator(new Kwf_Assets_Dependency_Iterator_UniqueFilter(new Kwf_Assets_Dependency_Iterator_Recursive($p->getDependency(), Kwf_Assets_Dependency_Abstract::DEPENDENCY_TYPE_ALL)), RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($it as $dep) {
             $progress->next(1, "{$dep}");
             if ($dep->getMimeType()) {
                 $mimeType = $dep->getMimeType();
                 $p->warmupDependencyCaches($dep, $mimeType, $progress);
                 if ($mimeType == 'text/css') {
                     $p->warmupDependencyCaches($dep, 'text/css; ie8', $progress);
                 }
             }
         }
     }
     $progress->finish();
     echo "generating package urls...\n";
     $steps = count($packages) * count($langs) * count($exts);
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(80);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     $allUrls = array();
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         foreach ($langs as $language) {
             foreach ($exts as $extension) {
                 $progress->next(1, "{$depName} {$extension} {$language}");
                 $urls = $p->getPackageUrls(self::$_mimeTypeByExtension[$extension], $language);
                 if (Kwf_Setup::getBaseUrl()) {
                     foreach ($urls as $k => $i) {
                         $urls[$k] = substr($i, strlen(Kwf_Setup::getBaseUrl()));
                     }
                 }
                 $cacheId = $p->getPackageUrlsCacheId(self::$_mimeTypeByExtension[$extension], $language);
                 Kwf_Assets_BuildCache::getInstance()->save($urls, $cacheId);
                 foreach ($urls as $url) {
                     if (!in_array($url, $allUrls)) {
                         $allUrls[] = $url;
                     }
                 }
             }
         }
     }
     echo "generating package contents...\n";
     $steps = count($allUrls) * 2;
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(80);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     foreach ($allUrls as $url) {
         if (substr($url, 0, 8) != '/assets/') {
             continue;
         }
         $param = explode('/', $url);
         if (count($param) != 7) {
             continue;
         }
         $dependencyClass = $param[3];
         $dependencyParams = $param[4];
         $urlLanguage = $param[5];
         $urlExtension = $param[6];
         $urlExtension = substr($urlExtension, 0, strpos($urlExtension, '?'));
         if (!class_exists($dependencyClass)) {
             throw new Kwf_Exception();
         }
         if (!is_instance_of($dependencyClass, 'Kwf_Assets_Interface_UrlResolvable')) {
             throw new Kwf_Exception();
         }
         $p = call_user_func(array($dependencyClass, 'fromUrlParameter'), $dependencyClass, $dependencyParams);
         if (!$p instanceof Kwf_Assets_Package) {
             throw new Kwf_Exception();
         }
         $contents = $p->getUrlContents($urlExtension, $urlLanguage);
         $progress->next(1, "{$p->getDependencyName()} {$urlExtension} {$urlLanguage} source");
         $cacheId = Kwf_Assets_Dispatcher::getInstance()->getCacheIdByPackage($p, $urlExtension, $urlLanguage);
         Kwf_Assets_BuildCache::getInstance()->save($contents, $cacheId);
         //save generated caches for clear-cache-watcher
         $fileName = 'build/assets/output-cache-ids-' . $urlExtension;
         if (!file_exists($fileName) || strpos(file_get_contents($fileName), $cacheId . "\n") === false) {
             file_put_contents($fileName, $cacheId . "\n", FILE_APPEND);
         }
         $contents = $p->getUrlContents($urlExtension . '.map', $urlLanguage);
         $progress->next(1, "{$p->getDependencyName()} {$urlExtension} {$urlLanguage} map");
         $cacheId = Kwf_Assets_Dispatcher::getInstance()->getCacheIdByPackage($p, $urlExtension . '.map', $urlLanguage);
         Kwf_Assets_BuildCache::getInstance()->save($contents, $cacheId);
     }
     Kwf_Assets_Cache::getInstance()->clean();
     Kwf_Assets_BuildCache::getInstance()->building = false;
 }