Updates index file with summary log data

@param string $indexFile path to index file
@param array $summary summary log data
@throws \yii\base\InvalidConfigException
510563
private function updateIndexFile($indexFile, $summary)
    {
        touch($indexFile);
        if (($fp = @fopen($indexFile, 'r+')) === false) {
            throw new InvalidConfigException("Unable to open debug data index file: $indexFile");
        }
        @flock($fp, LOCK_EX);
        $manifest = '';
        while (($buffer = fgets($fp)) !== false) {
            $manifest .= $buffer;
        }
        if (!feof($fp) || empty($manifest)) {
            // error while reading index data, ignore and create new
            $manifest = [];
        } else {
            $manifest = unserialize($manifest);
        }

        $manifest[$this->tag] = $summary;
        $this->gc($manifest);

        ftruncate($fp, 0);
        rewind($fp);
        fwrite($fp, serialize($manifest));

        @flock($fp, LOCK_UN);
        @fclose($fp);

        if ($this->module->fileMode !== null) {
            @chmod($indexFile, $this->module->fileMode);
        }
    }
257609
protected function generateCreateView(AbstractResourceBundle $bundle, &$summary)
    {
        $this->generateFormView($bundle);
        $path = $bundle->getPath() . '/Resources/views/' . $this->model . '/create.html.twig';

        if (file_exists($path)) {
            $summary[] = '';
            $summary[] = '<bg=red>Create view already exist.</>';

            return;
        }

        $this->renderFile('crud/create.html.twig.twig',
            $path,
            array(
                'bundle'  => $bundle->getName(),
                'model'   => $this->model,
                'prefix'  => $this->getBundlePrefix($bundle),
                'action'  => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_create'),
                'cancel'  => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_index'),
            )
        );

        $summary[] = '';
        $summary[] = '<bg=green>Create view created.</>';
    }
1140996
public function updateConfig(string $configFile, array $newData, ?bool $mergeDeep = false): bool
    {
        $this->load($configFile);
        if (!isset($this->data[$configFile])) {
            return false;
        }

        $oldData = $this->data[$configFile];
        $saveData = ($mergeDeep ? Arr::mergeRecursive($oldData, $newData) : Arr::merge($oldData, $newData));
        return $this->writeConfig($configFile, $saveData);
    }
327421
public function updateReport($idReport, $idSite, $description, $period, $hour, $reportType, $reportFormat, $reports, $parameters, $idSegment = false, $evolutionPeriodFor = 'prev',
                                 $evolutionPeriodN = null)
    {
        Piwik::checkUserIsNotAnonymous();
        Piwik::checkUserHasViewAccess($idSite);

        $scheduledReports = $this->getReports($idSite, $periodSearch = false, $idReport);
        $report   = reset($scheduledReports);
        $idReport = $report['idreport'];

        $currentUser = Piwik::getCurrentUserLogin();
        self::ensureLanguageSetForUser($currentUser);

        self::validateCommonReportAttributes($period, $hour, $description, $idSegment, $reportType, $reportFormat, $evolutionPeriodFor, $evolutionPeriodN);

        // report parameters validations
        $parameters = self::validateReportParameters($reportType, $parameters);

        // validation of requested reports
        $reports = self::validateRequestedReports($idSite, $reportType, $reports);

        $this->getModel()->updateReport($idReport, array(
            'description' => $description,
            'idsegment'   => $idSegment,
            'period'      => $period,
            'hour'        => $hour,
            'type'        => $reportType,
            'format'      => $reportFormat,
            'parameters'  => $parameters,
            'reports'     => $reports,
            'evolution_graph_within_period' => $evolutionPeriodFor == 'each',
            'evolution_graph_period_n' => $evolutionPeriodN ?: ImageGraph::getDefaultGraphEvolutionLastPeriods(),
        ));

        self::$cache = array();
    }
611459
protected function outdent(File $phpcsFile, int $index, int $count = 1): void
    {
        $tokens = $phpcsFile->getTokens();
        $char = $this->getIndentationCharacter($tokens[$index]['content'], true);

        $phpcsFile->fixer->replaceToken($index, $this->strReplaceOnce($char, '', $tokens[$index]['content']));
    }
337382
public function setAnalysis(Index $index, AnalysisFactoryInterface $analysis)
    {
        $index->create(
            array(
                'number_of_shards' => $this->numberOfShards,
                'number_of_replicas' => $this->numberOfReplicas,
                'analysis' => $analysis->build(),
            )
        );
    }
577234
protected function _downloadUpdate($updateUrl, $updateFile)
    {
        $this->log->addInfo(sprintf('Downloading update "%s" to "%s"', $updateUrl, $updateFile));
        if (function_exists('curl_version') && $this->_isValidUrl($updateUrl)) {
            $update = $this->_downloadCurl($updateUrl);
            if ($update === false) {
                return false;
            }
        } elseif (ini_get('allow_url_fopen')) {
            // TODO: Throw exception on error
            $update = @file_get_contents($updateUrl, false, $this->_useBasicAuth());

            if ($update === false) {
                $this->log->addError(sprintf('Could not download update "%s"!', $updateUrl));

                throw new DownloadException($updateUrl);
            }
        } else {
            throw new \Exception('No valid download method found!');
        }

        $handle = fopen($updateFile, 'w');
        if (!$handle) {
            $this->log->addError(sprintf('Could not open file handle to save update to "%s"!', $updateFile));

            return false;
        }

        if (!fwrite($handle, $update)) {
            $this->log->addError(sprintf('Could not write update to file "%s"!', $updateFile));
            fclose($handle);

            return false;
        }

        fclose($handle);

        return true;
    }
1235995
public void setSummary(java.lang.String summary) {
        getStateHelper().put(PropertyKeys.summary, summary);
        handleAttribute("summary", summary);
    }
1134869
public static function updateSite()
    {
        $update = "0";
        if(file_exists(PATH_HOME . "_config/updates/update.txt"))
            $update = file_get_contents(PATH_HOME . "_config/updates/update.txt");
        $update += 1;

        Helper::createFolderIfNoExist(PATH_HOME . "_config/updates");
        $f = fopen(PATH_HOME . "_config/updates/update.txt", "w+");
        fwrite($f, $update);
        fclose($f);
    }
774742
private void updateIndexName() {
        this.logIndexName = this.logIndexPrefix + "_" + SIMPLE_DATE_FORMAT.format(new Date());

        try {
            addIndex(logIndexName);
        } catch (IOException e) {
            logger.error("Failed to update log index name: {}", logIndexName, e);
        }
    }
242078
private void updateFile() {

        @SuppressWarnings("unchecked")
        List<Logger> logger = (List<Logger>)m_container.getItemIds();

        for (Logger item : logger) {
            m_container.getItem(item).getItemProperty(TableColumn.File).setValue(getLogFiles(item));
        }
        resetPageBuffer();
        refreshRenderedCells();
        refreshRowCache();
    }
9212
protected function updateLogFile()
    {
        // update file. $dtStr is '_Y-m-d' or '_Y-m-d_H'
        if ($this->fileIsChanged()) {
            fclose($this->fileHandle);

            $logFile = $this->genLogFile(true);
            $this->file = $logFile;
            $this->fileHandle = @fopen($logFile, 'ab');

            if (!$this->fileHandle) {
                $this->stderr("Could not open the log file {$logFile}");
            }
        }
    }
119272
protected function fixDocCommentOpenTags(File $phpCsFile, int $startIndex, int $endIndex): void
    {
        $tokens = $phpCsFile->getTokens();

        for ($i = $startIndex + 1; $i < $endIndex; $i++) {
            if ($tokens[$i]['code'] !== T_COMMENT) {
                continue;
            }

            if (!preg_match('|^\/\*\s*@\w+ (.+)|', $tokens[$i]['content'])) {
                continue;
            }

            $fix = $phpCsFile->addFixableError('Inline Doc Block comment should be using `/** ... */`', $i, 'InlineDocBlock');
            if ($fix) {
                $phpCsFile->fixer->beginChangeset();

                $comment = $tokens[$i]['content'];
                $comment = str_replace('/*', '/**', $comment);

                $phpCsFile->fixer->replaceToken($i, $comment);

                $phpCsFile->fixer->endChangeset();
            }
        }
    }
116023
public function update($indexName)
	{
		$index = $this->getRegistered($indexName);

		foreach ($index->getTypes() as $type => $typeBody) {
			$params = [
				'index' => $index->getInternalName(),
				'type'  => $type,
				'body'  => [$type => $typeBody]
			];

			$this->elasticSearcher->getClient()->indices()->putMapping($params);
		}
	}
922553
public function update($index, $data) {
        if (!$data instanceof Record) {
            $data = new Record(Utils::toArray($data));
        }
        $this->getFormat()->update($index, $data);
        // update buffer to reflect current changes
        if (isset($this->buffer[$index])) {
            $this->buffer[$index] = $data;
        }
    }
785012
@Override
    public synchronized void update(LogProviderConfig config) {
        // Get the configured log location, and derive the ffdc location from it
        File location = config.getLogDirectory();
        if (location == null) {
            location = new File(".");
        }
        location = new File(location, FFDCConfigurator.FFDC_DIR);

        ffdcLogDirectory = location;

        int maxFiles = config.getMaxFiles();

        // Creation and rolling of files should be done as the server
        Object token = ThreadIdentityManager.runAsServer();
        try {
            summaryLogSet.update(location,
                                 FFDCConfigurator.FFDC_SUMMARY_FILE_NAME,
                                 FFDCConfigurator.FFDC_EXTENSION,
                                 maxFiles);
            synchronized (ffdcLogSet) {
                ffdcLogSet.update(location,
                                  FFDCConfigurator.FFDC_FILE_NAME,
                                  FFDCConfigurator.FFDC_EXTENSION,
                                  0 /* unlimited */);
            }
        } finally {
            ThreadIdentityManager.reset(token);
        }
    }
1321630
private function updateFile()
    {
        if (is_null($this->file_path)) {
            throw new StorageException('Invalid file path');
        }

        file_put_contents(
            $this->file_path,
            serialize(
                [
                    'tokens' => $this->tokens,
                    'states' => $this->states
                ]
            )
        );
    }