public static function doCleanup()
    {
        Service::$log->msg('Cleanup started');
        foreach (self::$cleanupQueue as $cq) {
            Service::$log->msg(sprintf('Removing %s %s', $cq['type'], $cq['path']));

            if (strpos($cq['path'], self::$tempFolder) !== 0) {
                throw new \Exception(sprintf('Path "%s" is not within the defined temp folder location "%s".',
                    $cq['path'], self::$tempFolder));
            }

            if ($cq['type'] == self::TYPE_DIR) {
                system('rm -rf ' . $cq['path']);
            }

            if ($cq['type'] == self::TYPE_FILE) {
                system('rm ' . $cq['path']);
            }
        }

        Service::$log->msg('Cleanup ended');
    }