<commit_before><?php
/**
 * Dropbox adapter that extends much of the FileSystemLocal logic
 *
 * This class defines the functionality defined by FileSystemInterface for a plain Filesystem.
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class FileSystemDropboxBase 
{
  private $parent;
  public function __construct($parent)
  {
    $this->directoryMask = 'Y_m_F';
    $oauth = new Dropbox_OAuth_PHP(Utility::decrypt(getConfig()->get('credentials')->dropboxKey), Utility::decrypt(getConfig()->get('credentials')->dropboxSecret));
    $oauth->setToken(array(
      'token' => Utility::decrypt(getConfig()->get('credentials')->dropboxToken),
      'token_secret' => Utility::decrypt(getConfig()->get('credentials')->dropboxTokenSecret)
    ));
    $this->dropbox = new Dropbox_API($oauth);
    $this->dropboxFolder = getConfig()->get('dropbox')->dropboxFolder;
    $this->parent = $parent;
  }

  public function deletePhoto($id)
  {
    $photo = getDb()->getPhoto($id);
    $directory = urlencode(date($this->directoryMask, $photo['dateTaken']));
    try
    {
      $this->dropbox->delete(sprintf('%s/%s/%s', $this->dropboxFolder, $directory, basename($photo['pathOriginal'])));
      return true;
    }
    catch(Dropbox_Exception $e)
    {
      getLogger()->crit(sprintf('Could not delete photo (%s). Message: %s', $id, $e->getMessage()));
      return true;
    }
  }

  public function initialize()
  {
    $dropboxStatus = false;
    $folderDoesNotExist = false;
    try
    {
      $queryDropboxFolder = $this->dropbox->getMetaData($this->dropboxFolder);
      if(isset($queryDropboxFolder['is_deleted']) && $queryDropboxFolder['is_deleted'] == 1)
        $folderDoesNotExist = true;
      else
        $dropboxStatus = true;
    }
    catch(Dropbox_Exception_NotFound $e)
    {
      $folderDoesNotExist = true;
    }

    if($folderDoesNotExist)<commit_msg>Allow deletion even if file does not exist on Dropbox. Gh-205<commit_after><?php
/**
 * Dropbox adapter that extends much of the FileSystemLocal logic
 *
 * This class defines the functionality defined by FileSystemInterface for a plain Filesystem.
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class FileSystemDropboxBase 
{
  private $parent;
  public function __construct($parent)
  {
    $this->directoryMask = 'Y_m_F';
    $oauth = new Dropbox_OAuth_PHP(Utility::decrypt(getConfig()->get('credentials')->dropboxKey), Utility::decrypt(getConfig()->get('credentials')->dropboxSecret));
    $oauth->setToken(array(
      'token' => Utility::decrypt(getConfig()->get('credentials')->dropboxToken),
      'token_secret' => Utility::decrypt(getConfig()->get('credentials')->dropboxTokenSecret)
    ));
    $this->dropbox = new Dropbox_API($oauth);
    $this->dropboxFolder = getConfig()->get('dropbox')->dropboxFolder;
    $this->parent = $parent;
  }

  public function deletePhoto($id)
  {
    $photo = getDb()->getPhoto($id);
    $directory = urlencode(date($this->directoryMask, $photo['dateTaken']));
    try
    {
      $this->dropbox->delete(sprintf('%s/%s/%s', $this->dropboxFolder, $directory, basename($photo['pathOriginal'])));
    }
    catch(Dropbox_Exception_NotFound $e)
    {
      getLogger()->info('Photo does not exist on dropbox. Skipping delete operation.');
    }
    catch(Dropbox_Exception $e)
    {
      getLogger()->crit(sprintf('Could not delete photo (%s). Message: %s', $id, $e->getMessage()));
      return false;
    }
    return true;
  }

  public function initialize()
  {
    $dropboxStatus = false;
    $folderDoesNotExist = false;
    try
    {
      $queryDropboxFolder = $this->dropbox->getMetaData($this->dropboxFolder);
      if(isset($queryDropboxFolder['is_deleted']) && $queryDropboxFolder['is_deleted'] == 1)
        $folderDoesNotExist = true;
      else
        $dropboxStatus = true;
    }
    catch(Dropbox_Exception_NotFound $e)
    {
      $folderDoesNotExist = true;
    }

    if($folderDoesNotExist)
{'fraction_non_alphanumeric': 0.16066903193106943, 'fraction_numerical': 0.0012671059300557526, 'mean_word_length': 3.9898862199747156, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3742049', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1233, 'n_words': 228}