Trigger structure extractor

@param string $triggerName  Name of trigger to export
@return null
352196
private function getTriggerStructure($triggerName)
    {
        $stmt = $this->typeAdapter->show_create_trigger($triggerName);
        foreach ($this->dbHandler->query($stmt) as $r) {
            if ($this->dumpSettings['add-drop-trigger']) {
                $this->compressManager->write(
                    $this->typeAdapter->add_drop_trigger($triggerName)
                );
            }
            $this->compressManager->write(
                $this->typeAdapter->create_trigger($r)
            );
            return;
        }
    }
92369
protected function extractMessages($fileName, $translator)
    {
        $coloredFileName = Console::ansiFormat($fileName, [Console::FG_CYAN]);
        $this->stdout("Extracting messages from $coloredFileName...\n");

        $subject  = file_get_contents($fileName);
        $messages = [];
        foreach ((array)$translator as $currentTranslator) {
            $translatorTokens = token_get_all('<?php ' . $currentTranslator);
            array_shift($translatorTokens);

            $translatorTokensCount = count($translatorTokens);
            $matchedTokensCount = 0;
            $buffer = [];

            $tokens = token_get_all($subject);
            foreach ($tokens as $token) {
                // finding out translator call
                if ($matchedTokensCount < $translatorTokensCount) {
                    if ($this->tokensEqual($token, $translatorTokens[$matchedTokensCount])) {
                        $matchedTokensCount++;
                    } else {
                        $matchedTokensCount = 0;
                    }
                } elseif ($matchedTokensCount === $translatorTokensCount) {
                    // translator found
                    // end of translator call or end of something that we can't extract
                    if ($this->tokensEqual(')', $token)) {
                        if (isset($buffer[0][0], $buffer[1], $buffer[2][0]) && $buffer[0][0] === T_CONSTANT_ENCAPSED_STRING && $buffer[1] === ',' && $buffer[2][0] === T_CONSTANT_ENCAPSED_STRING) {
                            // is valid call we can extract

                            $category = stripcslashes($buffer[0][1]);
                            $category = mb_substr($category, 1, mb_strlen($category) - 2);

                            $message = stripcslashes($buffer[2][1]);
                            $message = mb_substr($message, 1, mb_strlen($message) - 2);

                            $messages[$category][] = $message;
                            foreach ($this->config['sourcePath'] as $sourcePath) {
                                $location = str_replace(realpath($sourcePath), '', $fileName);
                                if ( $location !== $fileName ) {
                                    $parts = explode('/', $sourcePath);
                                    $key   = count($parts) - 1;
                                    $this->locations[$category][] = [md5($message) => $parts[$key] . $location];
                                }
                            }
                        } else {
                            // invalid call or dynamic call we can't extract
                            $line = Console::ansiFormat($this->getLine($buffer), [Console::FG_CYAN]);
                            $skipping = Console::ansiFormat('Skipping line', [Console::FG_YELLOW]);
                            $this->stdout("$skipping $line. Make sure both category and message are static strings.\n");
                        }

                        // prepare for the next match
                        $matchedTokensCount = 0;
                        $buffer = [];
                    } elseif ($token !== '(' && isset($token[0]) && !in_array($token[0], [T_WHITESPACE, T_COMMENT])) {
                        // ignore comments, whitespaces and beginning of function call
                        $buffer[] = $token;
                    }
                }
            }
        }

        return $messages;
    }
425672
private function exportTables()
    {
        // Exporting tables one by one
        foreach ($this->tables as $table) {
            if ($this->matches($table, $this->dumpSettings['exclude-tables'])) {
                continue;
            }
            $this->getTableStructure($table);
            if (false === $this->dumpSettings['no-data']) { // don't break compatibility with old trigger
                $this->listValues($table);
            } elseif (true === $this->dumpSettings['no-data']
                 || $this->matches($table, $this->dumpSettings['no-data'])) {
                continue;
            } else {
                $this->listValues($table);
            }
        }
    }
668324
public function triggerEvent($eventName, $entity, $eventArgs = null, Event $event = null)
    {
        if (null === $event) {
            $event = new Event($entity, $eventArgs);
        }

        $this->dispatch($this->formatEventName($eventName, $entity), $event);

        if ($entity instanceof AbstractClassContent) {
            foreach (class_parents($entity) as $class) {
                if ($class === 'BackBee\ClassContent\AbstractClassContent') {
                    break;
                }

                $this->dispatch($this->formatEventName($eventName, $class), $event);
            }

            $this->dispatch(strtolower('classcontent.'.$eventName), $event);
        }
    }
117643
protected function getListeners($eventName)
    {
        if (isset($this->listeners[$eventName])) {
            return $this->listeners[$eventName];
        }
        return null;
    }
1007027
protected function extractTarFile($filename, $target)
    {
        $fileHandler = fopen($filename, 'r');
        $hardlinks = [];

        while (false === $this->isEof($fileHandler)) {
            $fields = $this->readBlockHeader($fileHandler, $filename);

            // deal with empty blocks in sparse files
            if (true === $fields['is_empty']) {
                continue;
            }

            if (false === $fields['is_valid_checksum']) {
                throw new Exception\IO\Input\FileCorruptedException($filename);
            }

            $name = $fields['name'];
            $type = $fields['type'];

            $location = $target . DIRECTORY_SEPARATOR . $name;
            switch ($type) {
                case self::TYPE_FILE:
                    $this->doExtractFile($location, $fields, $fileHandler);
                    break;
                case self::TYPE_DIRECTORY:
                    $this->doExtractDir($location);
                    break;
                case self::TYPE_HARD_LINK:
                    $hardlinks[$location] = $fields;
                    break;
                case self::TYPE_SYMBOLIC_LINK:
                    $this->doExtractSymLink($location, $fields);
                    break;
            }
        }

        // This should be done after extract all the files
        foreach ($hardlinks as $location => $fields) {
            $this->doExtractHardLink($location, $fields, $target);
        }

        fclose($fileHandler);

        return true;
    }
1026374
public function parse($trigger, $input)
    {
        $trigger = $this->parseTags($trigger, $input);

        $wildcards = [
            '/\*$/'             => '.*?',
            '/\*/'              => '\\w+?',
            '/#/'               => '\\d+?',
            '/_/'               => '[a-z]?',
            '/<zerowidthstar>/' => '^\*$',
        ];

        foreach ($wildcards as $pattern => $replacement) {
            $parsedTrigger = preg_replace($pattern, '('.$replacement.')', $trigger);

            if (@preg_match_all('/'.$parsedTrigger.'$/u', $input->source(), $stars)) {
                array_shift($stars);

                $stars = Collection::make($stars)->flatten()->all();

                synapse()->memory->shortTerm()->put('stars', $stars);

                return $this->triggerFound();
            }
        }

        return $this->triggerNotFound();
    }
962584
@Override
  public Trigger getTrigger(String triggerKey) throws SchedulerException {

    validateState();

    return quartzSchedulerResources.getJobStore().retrieveTrigger(triggerKey);
  }
801763
protected static function extractAjaxMethod($methodName)
    {
        $suffixLength = strlen(self::AJAX_METHOD_NAME_SUFFIX);

        return substr(
            $methodName,
            0,
            strlen($methodName) - $suffixLength
        );
    }
1316014
public static void removeTrigger(String triggerName) throws SundialSchedulerException {

    try {
      getScheduler().unscheduleJob(triggerName);
    } catch (SchedulerException e) {
      throw new SundialSchedulerException("ERROR REMOVING TRIGGER!!!", e);
    }
  }
666350
def trigger_delete_by_trigger_name(self, trigger_name, **kwargs):
        ""
        api_path = "/api/v2/triggers/{trigger_name}"
        api_path = api_path.format(trigger_name=trigger_name)
        return self.call(api_path, method="DELETE", **kwargs)
985235
protected function doResumeTrigger(Key $triggerKey)
    {
        if (false == $trigger = $this->retrieveTrigger($triggerKey)) {
            return;
        }

        if (false == $trigger->getNextFireTime()) {
            return;
        }

        $misfired = false;
        if (((int) $trigger->getNextFireTime()->format('U')) < time()) {
            $misfired = $this->updateMisfiredTrigger($triggerKey, Trigger::STATE_WAITING);
        }

        if (false == $misfired) {
            $trigger->setState(Trigger::STATE_WAITING);
            $result = $this->res->getTriggerStorage()->update($trigger);

            if (false == $result->isAcknowledged() || false == $result->getModifiedCount()) {
                throw new JobPersistenceException(sprintf('Couldn\'t resume trigger: "%s"', $triggerKey));
            }
        }
    }
909057
public function getTriggerByTemplate($template, $trigger_id = null) {
        $data = [ ];
        $data['template'] = $template;
        if (!is_null($trigger_id)) {
            $data['trigger_id'] = $trigger_id;
        }

        $result = $this->apiGet('trigger', $data);
        return $result;
    }
362402
public function doTriggeredJobComplete(Trigger $trigger, JobDetail $jobDetail, $triggerInstCode)
    {
        if ($triggerInstCode === CompletedExecutionInstruction::DELETE_TRIGGER) {
            // remove trigger
            $this->doRemoveTrigger($trigger->getKey());
        } elseif ($triggerInstCode === CompletedExecutionInstruction::SET_TRIGGER_COMPLETE) {
            $this->res->getTriggerStorage()->getCollection()->updateOne([
                'name' => $trigger->getKey()->getName(),
                'group' => $trigger->getKey()->getGroup(),
            ], [
                '$set' => [
                    'state' => Trigger::STATE_COMPLETE,
                    'errorMessage' => $trigger->getErrorMessage(),
                ]
            ]);
        } elseif ($triggerInstCode === CompletedExecutionInstruction::SET_TRIGGER_ERROR) {
            $this->res->getTriggerStorage()->getCollection()->updateOne([
                'name' => $trigger->getKey()->getName(),
                'group' => $trigger->getKey()->getGroup(),
            ], [
                '$set' => [
                    'state' => Trigger::STATE_ERROR,
                    'errorMessage' => $trigger->getErrorMessage(),
                ]
            ]);
        } elseif ($triggerInstCode === CompletedExecutionInstruction::SET_ALL_JOB_TRIGGERS_COMPLETE) {
            $this->res->getTriggerStorage()->getCollection()->updateMany([
                'jobName' => $trigger->getJobKey()->getName(),
                'jobGroup' => $trigger->getJobKey()->getGroup(),
            ], [
                '$set' => [
                    'state' => Trigger::STATE_COMPLETE,
                    'errorMessage' => $trigger->getErrorMessage(),
                ]
            ]);
        } elseif ($triggerInstCode === CompletedExecutionInstruction::SET_ALL_JOB_TRIGGERS_ERROR) {
            $this->res->getTriggerStorage()->getCollection()->updateMany([
                'jobName' => $trigger->getJobKey()->getName(),
                'jobGroup' => $trigger->getJobKey()->getGroup(),
            ], [
                '$set' => [
                    'state' => Trigger::STATE_ERROR,
                    'errorMessage' => $trigger->getErrorMessage(),
                ]
            ]);
        }

        // remove fired triggers
        // TODO: update fired trigger but not remove
        $result = $this->res->getFiredTriggerStorage()->getCollection()->deleteOne([
            'fireInstanceId' => $trigger->getFireInstanceId(),
        ]);

        if (false == $result->isAcknowledged() || false == $result->getDeletedCount()) {
            throw new JobPersistenceException(sprintf('Couldn\'t delete fired trigger: fireInstanceId "%s"', $trigger->getFireInstanceId()));
        }
    }
1274398
public function getResourcesBySourceName($sourceName)
    {
        // Getting source object first
        $source = $this->getSourceByName($sourceName);

        // Getting the data
        if ($source instanceof SourceInterface) {
            // Getting result iterator
            try {
                return $source->getContentIterator();
            } catch (\Exception $e) {
                throw new Exception\SourceGetDataException(
                    sprintf(
                        'Exception caught while getting the content for the following source object: %s',
                        $source->toString()
                    )
                );
            }
        }
        return null;
    }
850353
protected function extractPayload($eventName, $payload)
    {
        if (class_exists($eventName) && isset($payload[0]) && is_object($payload[0])) {
            return ExtractProperties::from($payload[0]);
        }

        return collect($payload)->map(function ($value) {
            return is_object($value) ? [
                'class' => get_class($value),
                'properties' => json_decode(json_encode($value), true),
            ] : $value;
        })->toArray();
    }
761651
public function trigger( $eventName, $event = null )
    {
        if ( null === $event )
        {
            $event = new SeedEvent( $this );
        }

        return EventManager::trigger( $eventName, $event );
    }