23use InvalidArgumentException;
54 $storedPathsByEntity = [];
55 foreach ( $depsBlobByEntity as $entity => $depsBlob ) {
56 $storedPathsByEntity[$entity] = json_decode( $depsBlob,
true );
60 foreach ( $entities as $entity ) {
61 $paths = $storedPathsByEntity[$entity] ?? [];
75 if ( !$dataByEntity ) {
79 $dbw = $this->getPrimaryDB();
84 foreach ( $dataByEntity as $entity => $data ) {
86 if ( !is_array( $data[self::KEY_PATHS] ) ) {
87 throw new InvalidArgumentException(
"Invalid entry for '$entity'" );
91 $paths = array_values( array_unique( $data[self::KEY_PATHS] ) );
92 sort( $paths, SORT_STRING );
93 $blob = json_encode( $paths, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
95 $existingBlob = $depsBlobByEntity[$entity] ??
null;
96 if (
$blob !== $existingBlob ) {
98 'md_module' => $module,
99 'md_skin' => $variant,
107 foreach ( $rows as $row ) {
111 [ [
'md_module',
'md_skin' ] ],
113 'md_deps' => $row[
'md_deps'],
123 public function remove(
$type, $entities ) {
131 $dbw = $this->getPrimaryDB();
133 $disjunctionConds = [];
134 foreach ( (array)$entities as $entity ) {
136 $disjunctionConds[] = $dbw->makeList(
137 [
'md_skin' => $variant,
'md_module' => $module ],
142 if ( $disjunctionConds ) {
145 $dbw->makeList( $disjunctionConds, $dbw::LIST_OR ),
164 $modulesByVariant = [];
165 foreach ( $entities as $entity ) {
167 $modulesByVariant[$variant][] = $module;
170 $disjunctionConds = [];
171 foreach ( $modulesByVariant as $variant =>
$modules ) {
172 $disjunctionConds[] = $db->
makeList(
173 [
'md_skin' => $variant,
'md_module' =>
$modules ],
178 $depsBlobByEntity = [];
180 if ( $disjunctionConds ) {
183 [
'md_module',
'md_skin',
'md_deps' ],
184 $db->
makeList( $disjunctionConds, $db::LIST_OR ),
188 foreach (
$res as $row ) {
189 $entity =
"{$row->md_module}|{$row->md_skin}";
190 $depsBlobByEntity[$entity] = $row->md_deps;
194 return $depsBlobByEntity;
202 ->getConnectionRef(
DB_REPLICA, [],
false, ( $this->lb )::CONN_TRX_AUTOCOMMIT );
210 ->getConnectionRef(
DB_PRIMARY, [],
false, ( $this->lb )::CONN_TRX_AUTOCOMMIT );
218 $parts = explode(
'|', $entity, 2 );
219 if ( count( $parts ) !== 2 ) {
220 throw new InvalidArgumentException(
"Invalid module entity '$entity'" );