Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
2
namespace Aws\Script\Composer;
2
namespace Aws\Script\Composer;
Línea 3... Línea 3...
3
 
3
 
-
 
4
use Composer\Script\Event;
4
use Composer\Script\Event;
5
use Symfony\Component\Filesystem\Exception\IOException;
Línea 5... Línea 6...
5
use Symfony\Component\Filesystem\Filesystem;
6
use Symfony\Component\Filesystem\Filesystem;
6
 
7
 
-
 
8
class Composer
7
class Composer
9
{
-
 
10
 
8
{
11
    public static function removeUnusedServicesInDev(Event $event, ?Filesystem $filesystem = null)
-
 
12
    {
-
 
13
        self::removeUnusedServicesWithConfig($event, $filesystem, true);
-
 
14
    }
-
 
15
 
9
    public static function removeUnusedServices(
16
    public static function removeUnusedServices(Event $event, ?Filesystem $filesystem = null)
10
        Event      $event,
17
    {
-
 
18
        self::removeUnusedServicesWithConfig($event, $filesystem, false);
-
 
19
    }
11
        Filesystem $filesystem = null
20
 
-
 
21
    private static function removeUnusedServicesWithConfig(Event $event, ?Filesystem $filesystem = null, $isDev = false)
-
 
22
    {
-
 
23
        if ($isDev && !$event->isDevMode()){
-
 
24
            return;
12
    )
25
        }
13
    {
26
 
14
        $composer = $event->getComposer();
27
        $composer = $event->getComposer();
15
        $extra = $composer->getPackage()->getExtra();
28
        $extra = $composer->getPackage()->getExtra();
16
        $listedServices = isset($extra['aws/aws-sdk-php'])
29
        $listedServices = isset($extra['aws/aws-sdk-php'])
Línea 81... Línea 94...
81
            ) {
94
            ) {
82
                $clientDir = $clientPath . $clientName;
95
                $clientDir = $clientPath . $clientName;
83
                $modelDir = $modelPath . $modelName;
96
                $modelDir = $modelPath . $modelName;
Línea 84... Línea 97...
84
 
97
 
-
 
98
                if ($filesystem->exists([$clientDir, $modelDir])) {
-
 
99
                    $attempts = 3;
-
 
100
                    $delay = 2;
-
 
101
 
-
 
102
                    while ($attempts) {
85
                if ($filesystem->exists([$clientDir, $modelDir])) {
103
                        try {
86
                    $filesystem->remove([$clientDir, $modelDir]);;
104
                            $filesystem->remove([$clientDir, $modelDir]);
-
 
105
                            $deleteCount++;
-
 
106
                            break;
-
 
107
                        } catch (IOException $e) {
-
 
108
                            $attempts--;
-
 
109
 
-
 
110
                            if (!$attempts) {
-
 
111
                                throw new IOException(
-
 
112
                                    "Removal failed after several attempts. Last error: " . $e->getMessage()
-
 
113
                                );
-
 
114
                            } else {
-
 
115
                                sleep($delay);
-
 
116
                                $event->getIO()->write(
-
 
117
                                    "Error encountered: " . $e->getMessage() . ". Retrying..."
-
 
118
                                );
-
 
119
                                $delay += 2;
-
 
120
                            }
-
 
121
                    }
-
 
122
                }
87
                    $deleteCount++;
123
 
88
                }
124
                }
89
            }
125
            }
90
        }
126
        }
91
        $event->getIO()->write(
127
        $event->getIO()->write(