Commit b07bee0f authored by Deepak Bhati's avatar Deepak Bhati 🎯 Committed by Rakesh Kumar
Browse files

Issue #3294454 by heni_deepak, Kumar Rakesh, radheymkumar: Phpcs Drupal standard coding issue

parent 4329073b
Loading
Loading
Loading
Loading
+44 −60
Original line number Diff line number Diff line
@@ -3,11 +3,7 @@
namespace Drupal\dl_file\Commands;

use Drush\Commands\DrushCommands;
use Drupal\Core\Database\Connection;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Drupal\media\Entity\Media;
use Drupal\file\Entity\File;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * A Drush commandfile.
 *
@@ -20,14 +16,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 *   - http://cgit.drupalcode.org/devel/tree/drush.services.yml
 */
class DlFileCommands extends DrushCommands {
    /**
     * {@inheritdoc}
    */
    public static function create(ContainerInterface $container) {
        return new static(
            $container->get('database')
        );
    }
     /**
     * @param String $dt1
     *   Argument with message to be displayed d1.
@@ -39,44 +27,47 @@ class DlFileCommands extends DrushCommands{
     *   date from to date to.

     * @option info
     *   about dl-file module.
     *   about dl_file module.

     * @option v-help
     *   Help.
     * @usage  dl_file:dl-file --date Y/m/d,dl-file --v-help
     */
    public function dl_file($dt1 = 'Command Not Executed. run dl-file --info to find more.', $options = ['date' => FALSE,'info' =>FALSE] ){
    public function dlFile ($dt1 = 'Command Not Executed. run dl-file --info to find more.', $options = ['date' => false,'info' =>false] ) {
        if($options['date']) {
            $vlid_date = date('Y/m/d', strtotime($dt1));
            $hrs = strtotime($dt1."+1 day");
            if($dt1 == $vlid_date) {
                $this->output()->writeln("\n<bg=cyan;options=bold;fg=white>Date formate is valid - ".$vlid_date."</>");
                $this->output()->writeln("<bg=cyan;options=bold;fg=white>Date formate is valid - ".$vlid_date."</>");
                $t1 = '12:00:00';
                $dt_s = $dt1.' '.$t1;
                $start_time = date('Y-m-d h:i:s', strtotime($dt_s));
                $st_time = strtotime($start_time);
                // load file based on created date.
                $database = \Drupal::database();
                $query = $database->select('file_managed', 'fm');
                $query->fields('fm',['fid']);
                $query->fields('fm',['uri']);
                $query->condition('fm.status', 1);
                $query->condition('fm.created',$hrs, '<=');
                $query = $database->select('file_managed', 'fm')
                    ->fields('fm', ['fid'])
                    ->fields('fm', ['uri'])
                    ->condition('fm.status', 1)
                    ->condition('fm.created', $hrs, '<=');
                // fatch file id.
                $resultEvent['Active'] = $query->execute()->fetchAll();
                $this->output()->writeln("<options=bold;fg=green>[ Total Files Found ] = [ ".count($resultEvent['Active'])." ]</>");
                $this->output()->writeln(
                    "<options=bold;fg=green>[ Total Files Found ] = [ ".count($resultEvent['Active'])." ]</>"
                );
                if ($resultEvent['Active'] != null) {
                    $this->output()->writeln("<info>\nFiles will be permanently delete from date</info><bg=black;options=bold;>\nFrom : ".date('Y-m-d h:i:s',$st_time)."\nTo : ".date('Y-m-d h:i:s',$hrs)."</>");
                    $this->output()->writeln(
                        "<info>\nFiles will be permanently delete from date</info>
                        <bg=black;options=bold;>\nFrom : ".date('Y-m-d h:i:s', $st_time)."\nTo : ".date('Y-m-d h:i:s', $hrs)."</>"
                    );
                    $fids[] = array();
                    $i=0;
                    if ($this->io()->confirm('<question>WARNING! Are you sure you want to delete these files?</question>')) {
                        $this->output()->writeln("<bg=cyan;>Processing Deletion........</>");
                    }
                    else{
                        $this->output()->writeln("<bg=cyan;>Processing Deletion</>");
                    } else {
                        throw new UserAbortException();
                    }
                    foreach ($resultEvent['Active'] as $value){
                        $fids[$i] = $value->fid;
                        $path = $value->uri;
                        
                        $file = basename($path);
                        $this->output()->writeln($file);
                        $mnth = date("m");
@@ -102,23 +93,16 @@ class DlFileCommands extends DrushCommands{
                        $query->condition('fid', $fids[$i], '=');
                        $resultEvent['Deactive'] = $query->execute();
                    }
                } else {
                    $this->output()->writeln("<options=bold;fg=white;bg=black>[ No matching images found. Use another date ]</>");
                }
                else{
                   $this->output()->writeln("<options=bold;fg=white;bg=black>[ No matching images found. Use another date ]</>\n"); 
                }
            }
            else{
            } else {
                $this->output()->writeln("<bg=red;options=bold;fg=white>Date Foramte is Wrong!</>");
                $this->output()->writeln("<options=bold;fg=white>run below commands \ndl-file --v-help \ndl-file --info</>"); 
            }
        }
        elseif($options['v-help']){
            $this->output()->writeln("<info>--date <option>     :     give a date with --date Year/Mont/Day</info>");
        }
        elseif($options['info']){
            $this->output()->writeln("\n<bg=yellow;fg=white;options=bold>This module is used to delete files from directory and database.</><options=bold;fg=blue>\n\nRun Below Command</><options=bold> \n\n drush dl-file --date <option> as <Y/m/d> to delete files from given date +1 day.\n drush dl-file --info to know about commands.</><options=bold;fg=blue>\n\nThank you.</>\n");
                $this->output()->writeln("<options=bold;fg=white>run below commands \ndl-file --info</>");
            }
        else{
        } elseif ($options['info']) {
            $this->output()->writeln("<bg=yellow;fg=white;options=bold>This module is used to delete files from directory and database.</><options=bold;fg=blue>\nRun Below Command</><options=bold> \n drush dl-file --date <option> as <Y/m/d> to delete files from given date +1 day.\n drush dl-file --info to know about commands.</><options=bold;fg=blue>\nThank you.</>");
        } else {
            $this->output()->writeln("<bg=red;options=bold;fg=white>".$dt1."</>");
        }
    }