<commit_before><?php

/**
 * This Extension can be applied to DataObjects that are accessible via a URL or that are associated to an object is
 * reachable via a URL.
 */
class CloudflarePurgerExtension extends DataExtension
{

    /**
     * Bit mask for purging the draft site.
     */
    const PURGE_DRAFT = 0b01;

    /**
     * Bit mask for purging the live version of the site.
     */
    const PURGE_LIVE = 0b10;

    /**
     * Bit mask for purging the both the draft and live version of the site.
     */
    const PURGE_ALL = 0b11;


    /**
     * This hook will be called on objects that have the `Versioned` extension applied on the them before a new version
     * is published.
     */
    public function onBeforeVersionedPublish()
    {
        $this->purge(self::PURGE_LIVE);
    }

    /**
     * This hook will be called after an object is saved. If the object doesn't implement the `Versioned` Extension, it
     * will try to purge URL from Cloudflare.
     */
    public function onAfterWrite()
    {
        if ($this->owner->hasExtension('Versioned')) {
            $this->purge(self::PURGE_DRAFT);
        } else {
            $this->purge(self::PURGE_LIVE);
        }
    }

    /**
     * Try to purge URLs from Cloudflare for this DataObject.
     *
     * @param int $purgeMask What we should purge
     */
    protected function purge($purgeMask = self::PURGE_LIVE)
    {
        // Get the links to purge
        $links = $this->getPurgeLinks();

        // If we have URLs, proceed with purge.
        if ($links) {
            try {
                if ($purgeMask & self::PURGE_LIVE) {
                    CloudflarePurger::purge($links);
                }

                if ($purgeMask & self::PURGE_DRAFT) {
                    $this->convertToStageUrl($links);
                    CloudflarePurger::purge($links);<commit_msg>Purge pages on Delete and add a function to Detect Site navifation changes.<commit_after><?php

/**
 * This Extension can be applied to DataObjects that are accessible via a URL or that are associated to an object is
 * reachable via a URL.
 */
class CloudflarePurgerExtension extends DataExtension
{

    /**
     * Bit mask for purging the draft site.
     */
    const PURGE_DRAFT = 0b01;

    /**
     * Bit mask for purging the live version of the site.
     */
    const PURGE_LIVE = 0b10;

    /**
     * Bit mask for purging the both the draft and live version of the site.
     */
    const PURGE_ALL = 0b11;


    /**
     * This hook will be called on objects that have the `Versioned` extension applied on the them before a new version
     * is published.
     */
    public function onBeforeVersionedPublish()
    {
        $this->purge(self::PURGE_LIVE);
    }

    /**
     * This hook will be called after an object is saved. If the object doesn't implement the `Versioned` Extension, it
     * will try to purge URL from Cloudflare.
     */
    public function onAfterWrite()
    {
        if ($this->owner)

        if ($this->owner->hasExtension('Versioned')) {
            $this->purge(self::PURGE_DRAFT);
        } else {
            $this->purge(self::PURGE_LIVE);
        }
    }

    /**
     * Purge the object after its been deleted.
     */
    public function onAfterDelete()
    {
        if ($this->owner->hasExtension('Versioned')) {
            $this->purge(self::PURGE_ALL);
        } else {
            $this->purge(self::PURGE_LIVE);
        }
    }

    /**
     * Detech alteration that will invalidate the site navigation.
     * @return boolean
     */
    protected function detectNavChange()
    {
        $changed = $this->owner->changed;

        return
            isset($changed['ShowInMenus']) ||
            isset($changed['Sort']) ||
            isset($changed['ParentID']) ||
            isset($changed['URLSegment'])||
            isset($changed['MenuTitle']);
    }

    /**
     * Try to purge URLs from Cloudflare for this DataObject.
     *
     * @param int $purgeMask What we should purge
     */
    protected function purge($purgeMask = self::PURGE_LIVE)
    {
        // Get the links to purge
        $links = $this->getPurgeLinks();

        // If we have URLs, proceed with purge.
        if ($links) {
            try {
                if ($purgeMask & self::PURGE_LIVE) {
                    CloudflarePurger::purge($links);
                }

                if ($purgeMask & self::PURGE_DRAFT) {
                    $this->convertToStageUrl($links);
                    CloudflarePurger::purge($links);
{'fraction_non_alphanumeric': 0.1051819184123484, 'fraction_numerical': 0.003969128996692392, 'mean_word_length': 1.9589041095890412, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4492988', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1282, 'n_words': 401}