Skip to content

Commit

Permalink
MDL-76219 lib: Change Box\Spout to OpenSpout library
Browse files Browse the repository at this point in the history
  • Loading branch information
meirzamoodle committed Jan 5, 2023
1 parent b2b17b9 commit 93220a6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dataformat/csv/classes/writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class writer extends \core\dataformat\spout_base {
protected $extension = ".csv";

/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::CSV;
protected $spouttype = \OpenSpout\Common\Type::CSV;

}

2 changes: 1 addition & 1 deletion dataformat/excel/classes/writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class writer extends \core\dataformat\spout_base {
protected $extension = ".xlsx";

/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::XLSX;
protected $spouttype = \OpenSpout\Common\Type::XLSX;

/**
* Set the title of the worksheet inside a spreadsheet
Expand Down
8 changes: 4 additions & 4 deletions dataformat/excel/tests/writer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ private function get_excel(string $content) {
$file = tempnam(sys_get_temp_dir(), 'excel_');
$handle = fopen($file, "w");
fwrite($handle, $content);
/** @var \Box\Spout\Reader\XLSX\Reader $reader */
$reader = \Box\Spout\Reader\Common\Creator\ReaderFactory::createFromType(\Box\Spout\Common\Type::XLSX);
/** @var \OpenSpout\Reader\XLSX\Reader $reader */
$reader = \OpenSpout\Reader\Common\Creator\ReaderFactory::createFromType(\OpenSpout\Common\Type::XLSX);
$reader->open($file);

/** @var \Box\Spout\Reader\XLSX\Sheet[] $sheets */
/** @var \OpenSpout\Reader\XLSX\Sheet[] $sheets */
$sheets = $reader->getSheetIterator();
$rowscellsvalues = [];
foreach ($sheets as $sheet) {
/** @var \Box\Spout\Common\Entity\Row[] $rows */
/** @var \OpenSpout\Common\Entity\Row[] $rows */
$rows = $sheet->getRowIterator();
foreach ($rows as $row) {
$thisvalues = [];
Expand Down
2 changes: 1 addition & 1 deletion dataformat/ods/classes/writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class writer extends \core\dataformat\spout_base {
protected $extension = ".ods";

/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::ODS;
protected $spouttype = \OpenSpout\Common\Type::ODS;

/**
* Set the title of the worksheet inside a spreadsheet
Expand Down
10 changes: 5 additions & 5 deletions dataformat/ods/tests/writer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ public function test_write_data(): void {
* Get ods rows from binary content
* @param string $content
* @return array
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
* @throws \OpenSpout\Common\Exception\IOException
* @throws \OpenSpout\Reader\Exception\ReaderNotOpenedException
*/
private function get_ods_rows_content($content) {
$reader = \Box\Spout\Reader\Common\Creator\ReaderFactory::createFromType(\Box\Spout\Common\Type::ODS);
$reader = \OpenSpout\Reader\Common\Creator\ReaderFactory::createFromType(\OpenSpout\Common\Type::ODS);
$file = tempnam(sys_get_temp_dir(), 'ods_');
$handle = fopen($file, "w");
fwrite($handle, $content);
$reader->open($file);
/** @var \Box\Spout\Reader\ODS\Sheet[] $sheets */
/** @var \OpenSpout\Reader\ODS\Sheet[] $sheets */
$sheets = $reader->getSheetIterator();
$rowscellsvalues = [];
foreach ($sheets as $sheet) {
/** @var \Box\Spout\Common\Entity\Row[] $rows */
/** @var \OpenSpout\Common\Entity\Row[] $rows */
$rows = $sheet->getRowIterator();
foreach ($rows as $row) {
$thisvalues = [];
Expand Down
10 changes: 5 additions & 5 deletions lib/classes/dataformat/spout_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class spout_base extends \core\dataformat\base {
* Output file headers to initialise the download of the file.
*/
public function send_http_headers() {
$this->writer = \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createWriter($this->spouttype);
$this->writer = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createWriter($this->spouttype);
if (method_exists($this->writer, 'setTempFolder')) {
$this->writer->setTempFolder(make_request_directory());
}
Expand All @@ -70,7 +70,7 @@ public function send_http_headers() {
* Set the dataformat to be output to current file
*/
public function start_output_to_file(): void {
$this->writer = \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createWriter($this->spouttype);
$this->writer = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createWriter($this->spouttype);
if (method_exists($this->writer, 'setTempFolder')) {
$this->writer->setTempFolder(make_request_directory());
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public function set_sheettitle($title) {
* @param array $columns
*/
public function start_sheet($columns) {
if ($this->sheettitle && $this->writer instanceof \Box\Spout\Writer\WriterMultiSheetsAbstract) {
if ($this->sheettitle && $this->writer instanceof \OpenSpout\Writer\WriterMultiSheetsAbstract) {
if ($this->renamecurrentsheet) {
$sheet = $this->writer->getCurrentSheet();
$this->renamecurrentsheet = false;
Expand All @@ -109,7 +109,7 @@ public function start_sheet($columns) {
}
$sheet->setName($this->sheettitle);
}
$row = \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray((array)$columns);
$row = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray((array)$columns);
$this->writer->addRow($row);
}

Expand All @@ -120,7 +120,7 @@ public function start_sheet($columns) {
* @param int $rownum
*/
public function write_record($record, $rownum) {
$row = \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($this->format_record($record));
$row = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($this->format_record($record));
$this->writer->addRow($row);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/db/renamedclasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@
'core_cohort\\local\\entities\\cohort' => 'core_cohort\\reportbuilder\\local\\entities\\cohort',
'core_cohort\\local\\entities\\cohort_member' => 'core_cohort\\reportbuilder\\local\\entities\\cohort_member',
'core_block\\local\\views\\secondary' => 'core_block\\navigation\\views\\secondary',
// Since Moodle 4.2.
'Box\\Spout' => 'OpenSpout',
];

0 comments on commit 93220a6

Please sign in to comment.