src/Jobs/Maintenance.php
public function cleanup_stale_data()
    {

        logger()->info('Performing stale data maintenance');

        // First cleanup characters.
        CharacterInfo::whereNotIn('character_id', function ($query) {

            $query->select('id')
                ->from((new User)->getTable());

        })->each(function ($character) {

            logger()->info('Cleaning up character: ' . $character->name);
            $character->delete();

        });

        // Next, cleanup corporations
        CorporationInfo::whereNotIn('corporation_id', function ($query) {

            // Filter out corporations that we have characters for.
            $query->select('corporation_id')
                ->from((new CharacterInfo)->getTable())
                ->whereIn('character_id', function ($sub_query) {

                    // Ensure that its characters with roles. Otherwise
                    // the corporation info is meaningless anyways.
                    $sub_query->select('character_id')
                        ->from((new CharacterRole)->getTable());

                });

        })->each(function ($corporation) {

            dump('Cleaning up corporation: ' . $corporation->name);
            logger()->info('Cleaning up corporation: ' . $corporation->name);
            $corporation->delete();

        });
    }
public function cleanup_stale_data()
    {

        logger()->info('Performing stale data maintenance');

        // First cleanup characters.
        CharacterInfo::whereNotIn('character_id', function ($query) {

            $query->select('id')
                ->from((new User)->getTable());

        })->each(function ($character) {

            logger()->info('Cleaning up character: ' . $character->name);
            $character->delete();

        });

        // Next, cleanup corporations
        CorporationInfo::whereNotIn('corporation_id', function ($query) {

            // Filter out corporations that we have characters for.
            $query->select('corporation_id')
                ->from((new CharacterInfo)->getTable())
                ->whereIn('character_id', function ($sub_query) {

                    // Ensure that its characters with roles. Otherwise
                    // the corporation info is meaningless anyways.
                    $sub_query->select('character_id')
                        ->from((new CharacterRole)->getTable());

                });

        })->each(function ($corporation) {

            dump('Cleaning up corporation: ' . $corporation->name);
            logger()->info('Cleaning up corporation: ' . $corporation->name);
            $corporation->delete();

        });
    }
public function cleanup_stale_data ( ) { logger ( ) -> info ( 'Performing stale data maintenance' ) ; // First cleanup characters. CharacterInfo :: whereNotIn ( 'character_id' , function ( $ query ) { $ query -> select ( 'id' ) -> from ( ( new User ) -> getTable ( ) ) ; } ) -> each ( function ( $ character ) { logger ( ) -> info ( 'Cleaning up character: ' . $ character -> name ) ; $ character -> delete ( ) ; } ) ; // Next, cleanup corporations CorporationInfo :: whereNotIn ( 'corporation_id' , function ( $ query ) { // Filter out corporations that we have characters for. $ query -> select ( 'corporation_id' ) -> from ( ( new CharacterInfo ) -> getTable ( ) ) -> whereIn ( 'character_id' , function ( $ sub_query ) { // Ensure that its characters with roles. Otherwise // the corporation info is meaningless anyways. $ sub_query -> select ( 'character_id' ) -> from ( ( new CharacterRole ) -> getTable ( ) ) ; } ) ; } ) -> each ( function ( $ corporation ) { dump ( 'Cleaning up corporation: ' . $ corporation -> name ) ; logger ( ) -> info ( 'Cleaning up corporation: ' . $ corporation -> name ) ; $ corporation -> delete ( ) ; } ) ; }
Cleans up stale data that relate to characters and
corporations that no longer have valid users.
Cleans up stale data that relate to characters and corporations that no longer have valid users .