ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMDCopyrightMigration Class Reference
+ Inheritance diagram for ilMDCopyrightMigration:
+ Collaboration diagram for ilMDCopyrightMigration:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 
 getPreconditions (Environment $environment)
 
 prepare (Environment $environment)
 
 step (Environment $environment)
 
 getRemainingAmountOfSteps ()
 

Protected Member Functions

 extractFields (string $copyright)
 
 translatePreInstalledLinksToSVG (string $image_link)
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Definition at line 25 of file class.ilMDCopyrightMigration.php.

Member Function Documentation

◆ extractFields()

ilMDCopyrightMigration::extractFields ( string  $copyright)
protected

Definition at line 83 of file class.ilMDCopyrightMigration.php.

References ilDBConstants\T_TEXT, and translatePreInstalledLinksToSVG().

Referenced by step().

83  : array
84  {
85  $full_name = '';
86  $link = '';
87  $image_link = '';
88  $alt_text = '';
89 
90  //find the image
91  if (preg_match('/<\s*img((?:.|\n)*?)\/>/i', $copyright, $img_matches)) {
92  if (preg_match('/src\s*=\s*(?:"|\')(.*?)(?:"|\')/i', $img_matches[1], $src_matches)) {
93  $image_link = strip_tags($src_matches[1]);
94  }
95  if (preg_match('/alt\s*=\s*(?:"|\')(.*?)(?:"|\')/i', $img_matches[1], $alt_matches)) {
96  $alt_text = strip_tags($alt_matches[1]);
97  }
98  }
99 
100  //find the link
101  if (preg_match('/<\s*a((?:.|\n)[^<]*?)<\s*\/a>/i', $copyright, $link_matches)) {
102  if (preg_match('/href\s*=\s*(?:"|\')(.*?)(?:"|\')/i', $link_matches[1], $name_matches)) {
103  $link = strip_tags($name_matches[1]);
104  }
105  if (preg_match('/>((?:\n|.)*)/i', $link_matches[1], $href_matches)) {
106  $full_name = strip_tags($href_matches[1]);
107  }
108  } else {
109  $full_name = strip_tags($copyright);
110  }
111 
112  $image_link = $this->translatePreInstalledLinksToSVG($image_link);
113 
114  return [
115  'full_name' => [\ilDBConstants::T_TEXT, $full_name],
116  'link' => [\ilDBConstants::T_TEXT, $link],
117  'image_link' => [\ilDBConstants::T_TEXT, $image_link],
118  'alt_text' => [\ilDBConstants::T_TEXT, $alt_text]
119  ];
120  }
translatePreInstalledLinksToSVG(string $image_link)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ilMDCopyrightMigration::getDefaultAmountOfStepsPerRun ( )

Definition at line 34 of file class.ilMDCopyrightMigration.php.

34  : int
35  {
36  return Migration::INFINITE;
37  }

◆ getLabel()

ilMDCopyrightMigration::getLabel ( )

Definition at line 29 of file class.ilMDCopyrightMigration.php.

29  : string
30  {
31  return "Migration of available copyrights.";
32  }

◆ getPreconditions()

ilMDCopyrightMigration::getPreconditions ( Environment  $environment)

◆ getRemainingAmountOfSteps()

ilMDCopyrightMigration::getRemainingAmountOfSteps ( )

Definition at line 73 of file class.ilMDCopyrightMigration.php.

References $res.

73  : int
74  {
75  $res = $this->db->query(
76  'SELECT COUNT(*) AS count FROM il_md_cpr_selections WHERE migrated = 0'
77  );
78 
79  $row = $this->db->fetchAssoc($res);
80  return (int) $row['count'];
81  }
$res
Definition: ltiservices.php:69

◆ prepare()

ilMDCopyrightMigration::prepare ( Environment  $environment)

Definition at line 48 of file class.ilMDCopyrightMigration.php.

References ILIAS\Setup\Environment\getResource().

48  : void
49  {
50  $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
51  }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
+ Here is the call graph for this function:

◆ step()

ilMDCopyrightMigration::step ( Environment  $environment)

Definition at line 53 of file class.ilMDCopyrightMigration.php.

References $res, extractFields(), and ilDBConstants\T_INTEGER.

53  : void
54  {
55  $res = $this->db->query(
56  'SELECT entry_id, copyright FROM il_md_cpr_selections WHERE migrated = 0 LIMIT 1'
57  );
58 
59  if ($row = $this->db->fetchAssoc($res)) {
60  if (!isset($row['entry_id'])) {
61  return;
62  }
63  $fields = $this->extractFields((string) ($row['copyright'] ?? ''));
64  $fields['migrated'] = [\ilDBConstants::T_INTEGER, 1];
65  $this->db->update(
66  'il_md_cpr_selections',
67  $fields,
68  ['entry_id' => [\ilDBConstants::T_INTEGER, (int) $row['entry_id']]]
69  );
70  }
71  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ translatePreInstalledLinksToSVG()

ilMDCopyrightMigration::translatePreInstalledLinksToSVG ( string  $image_link)
protected

Definition at line 122 of file class.ilMDCopyrightMigration.php.

Referenced by extractFields().

122  : string
123  {
124  $mapping = [
125  // 4.0
126  'https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-nd.svg',
127  'https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-sa.svg',
128  'https://i.creativecommons.org/l/by-nc/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc.svg',
129  'https://i.creativecommons.org/l/by-nd/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nd.svg',
130  'https://i.creativecommons.org/l/by-sa/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-sa.svg',
131  'https://i.creativecommons.org/l/by/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by.svg',
132  // 3.0
133  'http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-nd.svg',
134  'http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-sa.svg',
135  'http://i.creativecommons.org/l/by-nc/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc.svg',
136  'http://i.creativecommons.org/l/by-nd/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nd.svg',
137  'http://i.creativecommons.org/l/by-sa/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-sa.svg',
138  'http://i.creativecommons.org/l/by/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by.svg'
139  ];
140 
141  if (key_exists($image_link, $mapping)) {
142  return $mapping[$image_link];
143  }
144  return $image_link;
145  }
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilMDCopyrightMigration::$db
protected

Definition at line 27 of file class.ilMDCopyrightMigration.php.


The documentation for this class was generated from the following file: