Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php namespace Illuminate\Foundation;

use Carbon\Carbon;
use Illuminate\Filesystem\Filesystem;

class MigrationPublisher {

	/**
	 * A cache of migrations at a given destination.
	 *
	 * @var array
	 */
	protected $existing = array();

	/**
	 * Create a new migration publisher instance.
	 *
	 * @param  \Illuminate\Filesystem\Filesystem  $files
	 * @return void
	 */
	public function __construct(Filesystem $files)
	{
		$this->files = $files;
	}

	/**
	 * Publish the given package's migrations.
	 *
	 * @param  string  $source
	 * @param  string  $destination
	 * @return array
	 */
	public function publish($source, $destination)
	{
		$add = 0;

		$published = array();

		foreach ($this->getFreshMigrations($source, $destination) as $file)
		{
			$add++;

			$newName = $this->getNewMigrationName($file, $add);

			$this->files->copy(
				$file, $newName = $destination.'/'.$newName
			);

			$published[] = $newName;
		}

		return $published;
	}

	/**
	 * Get the fresh migrations for the source.
	 *
	 * @param  string  $source
	 * @param  string  $destination
	 * @return array
	 */
	protected function getFreshMigrations($source, $destination)
	{
		return array_filter($this->getPackageMigrations($source), function($file) use ($destination)
		{
			return ! $this->migrationExists($file, $destination);
		});
	}

	/**
	 * Determine if the migration is already published.
	 *
	 * @param  string  $migration
	 * @param  string  $destination
	 * @return bool
	 */
	public function migrationExists($migration, $destination)
	{
		$existing = $this->getExistingMigrationNames($destination);

		return in_array(substr(basename($migration), 18), $existing);
	}

	/**
	 * Get the existing migration names from the destination.
	 *
	 * @param  string  $destination
	 * @return array
	 */
	public function getExistingMigrationNames($destination)
	{
		if (isset($this->existing[$destination])) return $this->existing[$destination];

		return $this->existing[$destination] = array_map(function($file)
		{
			return substr(basename($file), 18);

		}, $this->files->files($destination));
	}

	/**
	 * Get the file list from the source directory.
	 *
	 * @param  string  $source
	 * @return array
	 */
	protected function getPackageMigrations($source)
	{
		$files = array_filter($this->files->files($source), function($file)
		{
			return ! starts_with($file, '.');
		});

		sort($files);

		return $files;
	}

	/**
	 * Get the new migration name.
	 *
	 * @param  string  $file
	 * @param  int  $add
	 * @return string
	 */
	protected function getNewMigrationName($file, $add)
	{
		return Carbon::now()->addSeconds($add)->format('Y_m_d_His').substr(basename($file), 17);
	}

}

Commits for Nextrek/Aiba_backup/vendor/laravel/framework/src/Illuminate/Foundation/MigrationPublisher.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000