Proyectos de Subversion LeadersLinked - Services

Rev

Rev 383 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 383 Rev 649
Línea 65... Línea 65...
65
        $this->translator = $translator;
65
        $this->translator = $translator;
Línea 66... Línea 66...
66
 
66
 
67
        parent::__construct();
67
        parent::__construct();
Línea -... Línea 68...
-
 
68
    }
-
 
69
 
-
 
70
    protected function configure(): void
-
 
71
    {
-
 
72
        $this->setName('leaderslinked:process-scheduled-content')
-
 
73
             ->setDescription('Procesa y libera el contenido programado de hábitos y habilidades')
-
 
74
             ->setHelp('Este comando verifica y procesa los hábitos programados para el día actual');
68
    }
75
    }
69
 
76
 
70
    protected function execute(InputInterface $input, OutputInterface $output): int
77
    protected function execute(InputInterface $input, OutputInterface $output): int
71
    {
-
 
72
        $output->writeln('Fin del proceso de liberación de contenido programado');
-
 
73
        
-
 
74
        
-
 
75
        $habitSkillMapper = \LeadersLinked\Mapper\HabitSkillMapper::getInstance($this->adapter);
-
 
Línea -... Línea 78...
-
 
78
    {
-
 
79
        $output->writeln('Iniciando proceso de liberación de contenido programado...');
-
 
80
        
-
 
81
        try {
76
        $habitSkills = $habitSkillMapper->fetchOne($id);
82
            // Obtener el día de la semana actual (1 = lunes, 7 = domingo)
-
 
83
            $currentDayNumber = (int)date('N');
-
 
84
            $currentTime = date('H:i:s');
-
 
85
            
-
 
86
            // Mapear el número del día a la columna correspondiente
-
 
87
            $dayColumns = [
-
 
88
                1 => ['active' => 'monday_active', 'time' => 'monday_time'],
-
 
89
                2 => ['active' => 'tuesday_active', 'time' => 'tuesday_time'],
-
 
90
                3 => ['active' => 'wednesday_active', 'time' => 'wednesday_time'],
-
 
91
                4 => ['active' => 'thursday_active', 'time' => 'thursday_time'],
-
 
92
                5 => ['active' => 'friday_active', 'time' => 'friday_time'],
-
 
93
                6 => ['active' => 'saturday_active', 'time' => 'saturday_time'],
-
 
94
                7 => ['active' => 'sunday_active', 'time' => 'sunday_time']
-
 
95
            ];
-
 
96
            
-
 
97
            $currentDayColumns = $dayColumns[$currentDayNumber];
-
 
98
            
-
 
99
            // Obtener el mapper de hábitos
-
 
100
            $habitSkillMapper = \LeadersLinked\Mapper\HabitSkillMapper::getInstance($this->adapter);
-
 
101
            
-
 
102
            // Construir la consulta para obtener hábitos programados para hoy
-
 
103
            $select = $habitSkillMapper->getSql()->select(HabitSkillMapper::_TABLE);
-
 
104
            $select->where([
-
 
105
                $currentDayColumns['active'] => 1,
-
 
106
                $currentDayColumns['time'] . ' <= ?' => $currentTime
77
        
107
            ]);
-
 
108
            
-
 
109
            $habits = $habitSkillMapper->executeFetchAllObject($select, new \LeadersLinked\Model\HabitSkill());
-
 
110
            
-
 
111
            $processedCount = 0;
-
 
112
            foreach ($habits as $habit) {
-
 
113
                try {
-
 
114
                    // Crear un registro para el hábito
-
 
115
                    $register = new \LeadersLinked\Model\HabitSkillRegister();
-
 
116
                    $register->network_id = $habit->network_id;
-
 
117
                    $register->user_id = $habit->user_id;
78
        
118
                    $register->skill_id = $habit->id;
-
 
119
                    $register->date = date('Y-m-d');
-
 
120
                    $register->uuid = uniqid();
-
 
121
                    
-
 
122
                    // Registrar el hábito
-
 
123
                    $registerMapper = \LeadersLinked\Mapper\HabitSkillRegisterMapper::getInstance($this->adapter);
-
 
124
                    if ($registerMapper->insert($register)) {
-
 
125
                        $processedCount++;
-
 
126
                        $this->logger->info(
-
 
127
                            sprintf('Hábito procesado: %s (Usuario: %d)', $habit->name, $habit->user_id),
-
 
128
                            ['habit_id' => $habit->id]
-
 
129
                        );
-
 
130
                    }
-
 
131
                } catch (\Exception $e) {
-
 
132
                    $this->logger->error(
-
 
133
                        sprintf('Error procesando hábito %d: %s', $habit->id, $e->getMessage()),
-
 
134
                        ['exception' => $e]
79
        
135
                    );
-
 
136
                }
80
        
137
            }
-
 
138
            
-
 
139
            $output->writeln(sprintf('Se procesaron %d hábitos programados', $processedCount));
-
 
140
            $output->writeln('Proceso de liberación de contenido programado completado con éxito');
-
 
141
            
-
 
142
            return Command::SUCCESS;
-
 
143
            
81
        
144
        } catch (\Exception $e) {
-
 
145
            $this->logger->error('Error en el proceso de contenido programado: ' . $e->getMessage());
82
 
146
            $output->writeln('<error>Error: ' . $e->getMessage() . '</error>');
83
        $output->writeln('Fin del proceso de liberación de contenido programado');
147
            
84
 
148
            return Command::FAILURE;
85
        return 0;
149
        }