<commit_before><?php

/*
 * This file is part of the Access to Memory (AtoM) software.
 *
 * Access to Memory (AtoM) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Access to Memory (AtoM) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Access to Memory (AtoM).  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Bulk export data to XML
 *
 * @package    symfony
 * @subpackage task
 * @author     <NAME> <<EMAIL>>
 */
class csvExportInformationObjectsTask extends exportBulkBaseTask
{
  protected $namespace        = 'csv';
  protected $name             = 'export';
  protected $briefDescription = 'Export descriptions as CSV file(s)';

  /**
   * @see sfTask
   */
  protected function configure()
  {
    $this->addCommonArgumentsAndOptions();
    $this->addOptions(array(
      new sfCommandOption('standard', null, sfCommandOption::PARAMETER_OPTIONAL, 'Description format ("isad" or "rad")', 'isad')
    ));
    $this->addOptions(array(
      new sfCommandOption('rows-per-file', null, sfCommandOption::PARAMETER_OPTIONAL, 'Rows per file (disregarded if writing to a file, not a directory)', false)
    ));
  }

  /**
   * @see sfTask
   */
  public function execute($arguments = array(), $options = array())
  {
    // Make sure standard is lower case
    $options['standard'] = $this->normalizeExportFormat(
      $options['standard'],
      array('isad', 'rad')
    );

    $configuration = ProjectConfiguration::getApplicationConfiguration('qubit', 'cli', false);
    $sf_context = sfContext::createInstance($configuration);

    // QubitSetting are not available for tasks? See lib/SiteSettingsFilter.class.php
    sfConfig::add(QubitSetting::getSettingsArray());

    $itemsExported = 0;

    $conn = $this->getDatabaseConnection();
    $rows = $conn->query($this->informationObjectQuerySql($options), PDO::FETCH_ASSOC);

    print 'Exporting as '. strtoupper($options['standard']) .".\n";

    // Instantiate CSV writer
    $writer = new csvInformationObjectExport(
      $arguments['path'],
      $options['standard'],
      $options['rows-per-file']
    );

    foreach ($rows as $row)
    {
      $sf_context->getUser()->setCulture($row['culture']);
      $resource = QubitInformationObject::getById($row['id']);

      // Don't export draft descriptions with public option
      if (isset($options['public']) && $options['public']
        && $resource->getPublicationStatus()->statusId == QubitTerm::PUBLICATION_STATUS_DRAFT_ID)
      {
        continue;
      }

      $writer->exportResource($resource);

      $this->indicateProgress($options['items-until-update']);

      $itemsExported++;
    }

    print "\nExport complete (". $itemsExported ." descriptions exported).\n";<commit_msg>Hide physical locations for --public ref #8993<commit_after><?php

/*
 * This file is part of the Access to Memory (AtoM) software.
 *
 * Access to Memory (AtoM) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Access to Memory (AtoM) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Access to Memory (AtoM).  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Bulk export data to XML
 *
 * @package    symfony
 * @subpackage task
 * @author     <NAME> <<EMAIL>>
 */
class csvExportInformationObjectsTask extends exportBulkBaseTask
{
  protected $namespace        = 'csv';
  protected $name             = 'export';
  protected $briefDescription = 'Export descriptions as CSV file(s)';

  /**
   * @see sfTask
   */
  protected function configure()
  {
    $this->addCommonArgumentsAndOptions();
    $this->addOptions(array(
      new sfCommandOption('standard', null, sfCommandOption::PARAMETER_OPTIONAL, 'Description format ("isad" or "rad")', 'isad')
    ));
    $this->addOptions(array(
      new sfCommandOption('rows-per-file', null, sfCommandOption::PARAMETER_OPTIONAL, 'Rows per file (disregarded if writing to a file, not a directory)', false)
    ));
  }

  /**
   * @see sfTask
   */
  public function execute($arguments = array(), $options = array())
  {
    // Make sure standard is lower case
    $options['standard'] = $this->normalizeExportFormat(
      $options['standard'],
      array('isad', 'rad')
    );

    $configuration = ProjectConfiguration::getApplicationConfiguration('qubit', 'cli', false);
    $sf_context = sfContext::createInstance($configuration);

    // QubitSetting are not available for tasks? See lib/SiteSettingsFilter.class.php
    sfConfig::add(QubitSetting::getSettingsArray());

    $itemsExported = 0;

    $conn = $this->getDatabaseConnection();
    $rows = $conn->query($this->informationObjectQuerySql($options), PDO::FETCH_ASSOC);

    print 'Exporting as '. strtoupper($options['standard']) .".\n";

    // Instantiate CSV writer
    $writer = new csvInformationObjectExport(
      $arguments['path'],
      $options['standard'],
      $options['rows-per-file']
    );

    $writer->setOptions($options);

    foreach ($rows as $row)
    {
      $sf_context->getUser()->setCulture($row['culture']);
      $resource = QubitInformationObject::getById($row['id']);

      // Don't export draft descriptions with public option
      if (isset($options['public']) && $options['public']
        && $resource->getPublicationStatus()->statusId == QubitTerm::PUBLICATION_STATUS_DRAFT_ID)
      {
        continue;
      }

      $writer->exportResource($resource);

      $this->indicateProgress($options['items-until-update']);

      $itemsExported++;
    }

    print "\nExport complete (". $itemsExported ." descriptions exported).\n";
{'fraction_non_alphanumeric': 0.1317793317793318, 'fraction_numerical': 0.0012432012432012432, 'mean_word_length': 3.6103151862464182, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4889728', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1777, 'n_words': 538}