Skip to content

Commit

Permalink
Merge branch 'MDL-76219-master' of https://github.com/meirzamoodle/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Jan 16, 2023
2 parents dd0580d + 3b4bc74 commit 574f68f
Show file tree
Hide file tree
Showing 192 changed files with 5,667 additions and 4,913 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
2 changes: 1 addition & 1 deletion lib/classes/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class core_component {
'Sabberworm\\CSS' => 'lib/php-css-parser',
'MoodleHQ\\RTLCSS' => 'lib/rtlcss',
'ScssPhp\\ScssPhp' => 'lib/scssphp',
'Box\\Spout' => 'lib/spout/src/Spout',
'OpenSpout' => 'lib/openspout/src',
'MatthiasMullie\\Minify' => 'lib/minify/matthiasmullie-minify/src/',
'MatthiasMullie\\PathConverter' => 'lib/minify/matthiasmullie-pathconverter/src/',
'IMSGlobal\LTI' => 'lib/ltiprovider/src',
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',
];
21 changes: 21 additions & 0 deletions lib/openspout/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 openspout

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions lib/openspout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# OpenSpout

[![Latest Stable Version](https://poser.pugx.org/openspout/openspout/v/stable)](https://packagist.org/packages/openspout/openspout)
[![Build Status](https://github.com/openspout/openspout/actions/workflows/ci.yml/badge.svg)](https://github.com/openspout/openspout/actions/workflows/ci.yml)
[![Code Coverage](https://codecov.io/gh/openspout/openspout/coverage.svg?branch=main)](https://codecov.io/gh/openspout/openspout?branch=main)
[![Total Downloads](https://poser.pugx.org/openspout/openspout/downloads)](https://packagist.org/packages/openspout/openspout)

OpenSpout is a community driven fork of `box/spout`, a PHP library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way.
Unlike other file readers or writers, it is capable of processing very large files, while keeping the memory usage really low (less than 3MB).

## Documentation

Documentation can be found at [https://openspout.readthedocs.io/en/latest/](https://openspout.readthedocs.io/en/latest/).

## Requirements

* PHP version 7.3 or higher
* PHP extension `php_zip` enabled
* PHP extension `php_xmlreader` enabled

## Upgrade from `box/spout`

1. Replace `box/spout` with `openspout/openspout` in your `composer.json`
2. Replace `Box\Spout` with `OpenSpout` in your code

## Upgrade guide

Version 3 introduced new functionality but also some breaking changes. If you want to upgrade your Spout codebase from version 2 please consult the [Upgrade guide](UPGRADE-3.0.md).

## Running tests

The `main` branch includes unit, functional and performance tests.
If you just want to check that everything is working as expected, executing the unit and functional tests is enough.

* `phpunit` - runs unit and functional tests
* `phpunit --group perf-tests` - only runs the performance tests

For information, the performance tests take about 10 minutes to run (processing 1 million rows files is not a quick thing).

> Performance tests status: [![Build Status](https://travis-ci.org/box/spout.svg?branch=perf-tests)](https://travis-ci.org/box/spout)
## Copyright and License

This is a fork of Box's Spout library: https://github.com/box/spout

Code until and directly descending from commit [`cc42c1d`](https://github.com/openspout/openspout/commit/cc42c1d29fc5d29f07caeace99bd29dbb6d7c2f8)
is copyright of _Box, Inc._ and licensed under the Apache License, Version 2.0:

https://github.com/openspout/openspout/blob/cc42c1d29fc5d29f07caeace99bd29dbb6d7c2f8/LICENSE

Code created, edited and released after the commit mentioned above
is copyright of _openspout_ Github organization and licensed under MIT License.

https://github.com/openspout/openspout/blob/main/LICENSE
10 changes: 10 additions & 0 deletions lib/openspout/readme_moodle.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
OpenSpout
---------

Downloaded from: https://github.com/openspout/openspout

Import procedure:

* Copy all the files from the folder 'src' directory.
* Copy the LICENSE & README.md files from the project root.
* Update lib/thirdpartylibs.xml with the latest version.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace Box\Spout\Autoloader;
namespace OpenSpout\Autoloader;

/**
* Class Psr4Autoloader
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md#class-example
*/
class Psr4Autoloader
Expand All @@ -18,52 +17,50 @@ class Psr4Autoloader

/**
* Register loader with SPL autoloader stack.
*
* @return void
*/
public function register()
{
\spl_autoload_register([$this, 'loadClass']);
spl_autoload_register([$this, 'loadClass']);
}

/**
* Adds a base directory for a namespace prefix.
*
* @param string $prefix The namespace prefix.
* @param string $baseDir A base directory for class files in the
* namespace.
* @param bool $prepend If true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last.
* @return void
* @param string $prefix the namespace prefix
* @param string $baseDir a base directory for class files in the
* namespace
* @param bool $prepend if true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last
*/
public function addNamespace($prefix, $baseDir, $prepend = false)
{
// normalize namespace prefix
$prefix = \trim($prefix, '\\') . '\\';
$prefix = trim($prefix, '\\').'\\';

// normalize the base directory with a trailing separator
$baseDir = \rtrim($baseDir, DIRECTORY_SEPARATOR) . '/';
$baseDir = rtrim($baseDir, \DIRECTORY_SEPARATOR).'/';

// initialize the namespace prefix array
if (isset($this->prefixes[$prefix]) === false) {
if (false === isset($this->prefixes[$prefix])) {
$this->prefixes[$prefix] = [];
}

// retain the base directory for the namespace prefix
if ($prepend) {
\array_unshift($this->prefixes[$prefix], $baseDir);
array_unshift($this->prefixes[$prefix], $baseDir);
} else {
\array_push($this->prefixes[$prefix], $baseDir);
$this->prefixes[$prefix][] = $baseDir;
}
}

/**
* Loads the class file for a given class name.
*
* @param string $class The fully-qualified class name.
* @return mixed The mapped file name on success, or boolean false on
* failure.
* @param string $class the fully-qualified class name
*
* @return mixed the mapped file name on success, or boolean false on
* failure
*/
public function loadClass($class)
{
Expand All @@ -72,22 +69,22 @@ public function loadClass($class)

// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while (($pos = \strrpos($prefix, '\\')) !== false) {
while (($pos = strrpos($prefix, '\\')) !== false) {
// retain the trailing namespace separator in the prefix
$prefix = \substr($class, 0, $pos + 1);
$prefix = substr($class, 0, $pos + 1);

// the rest is the relative class name
$relativeClass = \substr($class, $pos + 1);
$relativeClass = substr($class, $pos + 1);

// try to load a mapped file for the prefix and relative class
$mappedFile = $this->loadMappedFile($prefix, $relativeClass);
if ($mappedFile !== false) {
if (false !== $mappedFile) {
return $mappedFile;
}

// remove the trailing namespace separator for the next iteration
// of strrpos()
$prefix = \rtrim($prefix, '\\');
$prefix = rtrim($prefix, '\\');
}

// never found a mapped file
Expand All @@ -97,15 +94,16 @@ public function loadClass($class)
/**
* Load the mapped file for a namespace prefix and relative class.
*
* @param string $prefix The namespace prefix.
* @param string $relativeClass The relative class name.
* @return mixed Boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded.
* @param string $prefix the namespace prefix
* @param string $relativeClass the relative class name
*
* @return mixed boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded
*/
protected function loadMappedFile($prefix, $relativeClass)
{
// are there any base directories for this namespace prefix?
if (isset($this->prefixes[$prefix]) === false) {
if (false === isset($this->prefixes[$prefix])) {
return false;
}

Expand All @@ -115,8 +113,8 @@ protected function loadMappedFile($prefix, $relativeClass)
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $baseDir
. \str_replace('\\', '/', $relativeClass)
. '.php';
.str_replace('\\', '/', $relativeClass)
.'.php';

// if the mapped file exists, require it
if ($this->requireFile($file)) {
Expand All @@ -132,12 +130,13 @@ protected function loadMappedFile($prefix, $relativeClass)
/**
* If a file exists, require it from the file system.
*
* @param string $file The file to require.
* @return bool True if the file exists, false if not.
* @param string $file the file to require
*
* @return bool true if the file exists, false if not
*/
protected function requireFile($file)
{
if (\file_exists($file)) {
if (file_exists($file)) {
require $file;

return true;
Expand Down
15 changes: 15 additions & 0 deletions lib/openspout/src/Autoloader/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace OpenSpout\Autoloader;

require_once 'Psr4Autoloader.php';

/**
* @var string
* Full path to "src/Spout" which is what we want "OpenSpout" to map to
*/
$srcBaseDirectory = \dirname(__DIR__);

$loader = new Psr4Autoloader();
$loader->register();
$loader->addNamespace('OpenSpout', $srcBaseDirectory);
Loading

0 comments on commit 574f68f

Please sign in to comment.