<commit_before><?php

/**
 * Manage the CDN Trash
 *
 * @package     Nails
 * @subpackage  module-cdn
 * @category    AdminController
 * @author      Nails Dev Team
 * @link
 */

namespace Nails\Admin\Cdn;

use Nails\Factory;
use Nails\Admin\Helper;
use Nails\Cdn\Controller\BaseAdmin;

class Utilities extends BaseAdmin
{
    /**
     * Announces this controller's navGroups
     * @return stdClass
     */
    public static function announce()
    {
        $oNavGroup = Factory::factory('Nav', 'nailsapp/module-admin');
        $oNavGroup->setLabel('Utilities');
        $oNavGroup->setIcon('fa-sliders');

        if (userHasPermission('admin:cdn:utilities:findOrphan')) {

            $oNavGroup->addAction('CDN: Find orphaned objects');
        }

        return $oNavGroup;
    }

    // --------------------------------------------------------------------------

    /**
     * Returns an array of permissions which can be configured for the user
     * @return array
     */
    public static function permissions()
    {
        $permissions = parent::permissions();

        $permissions['findOrphan'] = 'Can find orphans';

        return $permissions;
    }

    // --------------------------------------------------------------------------

    /**
     * Find orphaned CDN objects
     * @return void
     */
    public function index()
    {
        if (!userHasPermission('admin:cdn:utilities:findOrphan')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        if ($this->input->is_cli_request()) {

            return $this->indexCli();
        }

        // --------------------------------------------------------------------------

        if ($this->input->post()) {

            //  A little form validation
            $type   = $this->input->post('type');
            $parser = $this->input->post('parser');
            $error  = '';

            if ($type == 'db' && $parser == 'create') {

                $error  = 'Cannot use "Add to database" results parser when finding orphaned database objects.';
            }


            if (empty($error)) {

                switch ($type) {

                    case 'db':

                        $this->data['orphans']  = $this->cdn->findOrphanedObjects();
                        break;

                    //  @TODO
                    case 'file':

                        $this->data['message']  = '<strong>TODO:</strong> find orphaned files.';
                        break;

                    //  Invalid request
                    default:

                        $this->data['error']    = 'Invalid search type.';
                        break;
                }

                if (isset($this->data['orphans'])) {

                    switch ($parser) {

                        case 'list':

                            $this->data['success'] = '<strong>Search complete!</strong> your results are show below.';
                            break;

                        //  @todo: keep the unset(), it prevents the table from rendering
                        case 'purge':

                            $this->data['message'] = '<strong>TODO:</strong> purge results.';
                            unset($this->data['orphans']);
                            break;

                        case 'create':

                            $this->data['message'] = '<strong>TODO:</strong> create objects using results.';
                            unset($this->data['orphans']);
                            break;

                        //  Invalid request
                        default:

                            $this->data['error'] = 'Invalid result parse selected.';
                            unset($this->data['orphans']);
                            break;
                    }
                }

            } else {

                $this->data['error'] = 'An error occurred. ' . $error;
            }
        }

        // --------------------------------------------------------------------------

        $this->data['page']->title = 'CDN: Find Orphaned Objects';

        // --------------------------------------------------------------------------

        $this->asset->load('admin.utilities.orphans.min.js', true);
        $this->asset->inline(
            'var _Admin_Utilities_Cdn_Orphans = new NAILS_Admin_Utilities_Cdn_Orphans();
            _Admin_Utilities_Cdn_Orphans.init();',
            'JS'
        );

        // --------------------------------------------------------------------------

        Helper::loadView('index');
    }

    // --------------------------------------------------------------------------

    /**
     * Find orphaned CDN objects (command line)
     * @return void
     */
    protected function indexCli()
    {
        //  @TODO: Complete CLI functionality for report generating
        echo 'Sorry, this functionality is not complete yet. If you are experiencing timeouts please increase the timeout limit for PHP.';
    }
}<commit_msg>Fix: incorrectly loaded module asset<commit_after><?php

/**
 * Manage the CDN Trash
 *
 * @package     Nails
 * @subpackage  module-cdn
 * @category    AdminController
 * @author      Nails Dev Team
 * @link
 */

namespace Nails\Admin\Cdn;

use Nails\Factory;
use Nails\Admin\Helper;
use Nails\Cdn\Controller\BaseAdmin;

class Utilities extends BaseAdmin
{
    /**
     * Announces this controller's navGroups
     * @return stdClass
     */
    public static function announce()
    {
        $oNavGroup = Factory::factory('Nav', 'nailsapp/module-admin');
        $oNavGroup->setLabel('Utilities');
        $oNavGroup->setIcon('fa-sliders');

        if (userHasPermission('admin:cdn:utilities:findOrphan')) {

            $oNavGroup->addAction('CDN: Find orphaned objects');
        }

        return $oNavGroup;
    }

    // --------------------------------------------------------------------------

    /**
     * Returns an array of permissions which can be configured for the user
     * @return array
     */
    public static function permissions()
    {
        $permissions = parent::permissions();

        $permissions['findOrphan'] = 'Can find orphans';

        return $permissions;
    }

    // --------------------------------------------------------------------------

    /**
     * Find orphaned CDN objects
     * @return void
     */
    public function index()
    {
        if (!userHasPermission('admin:cdn:utilities:findOrphan')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        if ($this->input->is_cli_request()) {

            return $this->indexCli();
        }

        // --------------------------------------------------------------------------

        if ($this->input->post()) {

            //  A little form validation
            $type   = $this->input->post('type');
            $parser = $this->input->post('parser');
            $error  = '';

            if ($type == 'db' && $parser == 'create') {

                $error  = 'Cannot use "Add to database" results parser when finding orphaned database objects.';
            }


            if (empty($error)) {

                switch ($type) {

                    case 'db':

                        $this->data['orphans']  = $this->cdn->findOrphanedObjects();
                        break;

                    //  @TODO
                    case 'file':

                        $this->data['message']  = '<strong>TODO:</strong> find orphaned files.';
                        break;

                    //  Invalid request
                    default:

                        $this->data['error']    = 'Invalid search type.';
                        break;
                }

                if (isset($this->data['orphans'])) {

                    switch ($parser) {

                        case 'list':

                            $this->data['success'] = '<strong>Search complete!</strong> your results are show below.';
                            break;

                        //  @todo: keep the unset(), it prevents the table from rendering
                        case 'purge':

                            $this->data['message'] = '<strong>TODO:</strong> purge results.';
                            unset($this->data['orphans']);
                            break;

                        case 'create':

                            $this->data['message'] = '<strong>TODO:</strong> create objects using results.';
                            unset($this->data['orphans']);
                            break;

                        //  Invalid request
                        default:

                            $this->data['error'] = 'Invalid result parse selected.';
                            unset($this->data['orphans']);
                            break;
                    }
                }

            } else {

                $this->data['error'] = 'An error occurred. ' . $error;
            }
        }

        // --------------------------------------------------------------------------

        $this->data['page']->title = 'CDN: Find Orphaned Objects';

        // --------------------------------------------------------------------------

        $this->asset->load('admin.utilities.orphans.min.js', 'nailsapp/module-cdn');
        $this->asset->inline(
            'var _Admin_Utilities_Cdn_Orphans = new NAILS_Admin_Utilities_Cdn_Orphans();
            _Admin_Utilities_Cdn_Orphans.init();',
            'JS'
        );

        // --------------------------------------------------------------------------

        Helper::loadView('index');
    }

    // --------------------------------------------------------------------------

    /**
     * Find orphaned CDN objects (command line)
     * @return void
     */
    protected function indexCli()
    {
        //  @TODO: Complete CLI functionality for report generating
        echo 'Sorry, this functionality is not complete yet. If you are experiencing timeouts please increase the timeout limit for PHP.';
    }
}
{'fraction_non_alphanumeric': 0.2280408724700334, 'fraction_numerical': 0.0, 'mean_word_length': 1.0289017341040463, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 83, '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': '1339813', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2275, 'n_words': 526}