<commit_before><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Import extends CI_Controller {

	public function __construct()
  {
	  
	  parent::__construct();
	  
	  // Set a different basic authentication for this controller only
/*
	  if (!isset($_SERVER['PHP_AUTH_USER']) || 
	      $_SERVER['PHP_AUTH_USER'] != $this->config->item('admin_username') || 
	      $_SERVER['PHP_AUTH_PW'] != $this->config->item('admin_password')) {
          header('WWW-Authenticate: Basic realm="GreyPix"');
          header('HTTP/1.0 401 Unauthorized');
          die('Access Denied');
    }
*/
	  
	  // Load library
	  $this->load->library('flickr');
	  
	  // Load models
	  $this->load->model('Greypix_model', 'gpdb');
	  
  }
	
	public function index()
	{
	  // TO DO:
  	// create page that has 3 buttons
  	// 1 button to update the albums
  	// 1 button to update the photos
  	// 1 button to update both
  	$this->import_albums(true);
	}
	
	public function authenticate_app()
	{
  	
  	unset($_SESSION['phpFlickr_auth_token']);
    
    $default_redirect = "/import/import-albums/";
     
  	if ( isset($_SESSION['phpFlickr_auth_redirect']) && !empty($_SESSION['phpFlickr_auth_redirect']) ) {
  		$redirect = $_SESSION['phpFlickr_auth_redirect'];
  		unset($_SESSION['phpFlickr_auth_redirect']);
  	}
  	
    if (empty($_GET['frob'])) {
      $this->flickr->f->auth($permissions, true);
    } else {
      $this->flickr->f->auth_getToken($_GET['frob']);
    }
    
    if (empty($redirect)) {
  		header("Location: " . $default_redirect);
    } else {
	  	header("Location: " . $redirect);
    }
  	
	}
	
	private function getAllAlbums()
	{
    
    $albums = $this->flickr->f->photosets_getList($this->config->item('flickr_user_id'));
    return $albums;
    
	}
	
	public function import_albums()
	{
    
    $frob           = $this->flickr->f->auth();
    $token          = $this->flickr->f->auth_checkToken();  
    $albums         = $this->getAllAlbums();
    $newAlbums      = 0;
    $updatedAlbums  = 0;
    $deletedAlbums  = 0;
    $msg            = "";
    
    if ($albums) {
      
      foreach ($albums['photoset'] as $album) {
        
        $payload = array("id"           => $album['id'],
                         "title"        => $album['title'],
                         "description"  => $album['description'],
                         "primary"      => $album['primary'],
                         "photos"       => $album['photos'],
                         "date_create"  => $album['date_create'],
                         "date_update"  => $album['date_update']
                        );
        echo "<pre>"; print_r($album); echo "</pre>";
        
        echo "<pre>"; print_r($payload); echo "</pre>";
        
        // check if album exists in database
        $albumExists = $this->gpdb->getAlbumByID($album['id']);
        
        echo "<pre>"; print_r($albumExists); echo "</pre>";exit;
        
        // if no records come back
        if (!$albumExists) {
          // insert album into database
          $this->gpdb->insertIntoDB($payload, "albums");  
          $newAlbums++;
        } else {
          // check if up-to-date
          if ($album['date_update'] > $albumExists->date_update) {
            // update record
            $this->gpdb->insertIntoDB($payload, "albums", $album['id']);
            $updatedAlbums++;
          }
        }
        
        // get all photos in this album<commit_msg>payload sent is not reflecting what is showing up in the database<commit_after><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Import extends CI_Controller {

	public function __construct()
  {
	  
	  parent::__construct();
	  
	  // Set a different basic authentication for this controller only
/*
	  if (!isset($_SERVER['PHP_AUTH_USER']) || 
	      $_SERVER['PHP_AUTH_USER'] != $this->config->item('admin_username') || 
	      $_SERVER['PHP_AUTH_PW'] != $this->config->item('admin_password')) {
          header('WWW-Authenticate: Basic realm="GreyPix"');
          header('HTTP/1.0 401 Unauthorized');
          die('Access Denied');
    }
*/
	  
	  // Load library
	  $this->load->library('flickr');
	  
	  // Load models
	  $this->load->model('Greypix_model', 'gpdb');
	  
  }
	
	public function index()
	{
	  // TO DO:
  	// create page that has 3 buttons
  	// 1 button to update the albums
  	// 1 button to update the photos
  	// 1 button to update both
  	$this->import_albums(true);
	}
	
	public function authenticate_app()
	{
  	
  	unset($_SESSION['phpFlickr_auth_token']);
    
    $default_redirect = "/import/import-albums/";
     
  	if ( isset($_SESSION['phpFlickr_auth_redirect']) && !empty($_SESSION['phpFlickr_auth_redirect']) ) {
  		$redirect = $_SESSION['phpFlickr_auth_redirect'];
  		unset($_SESSION['phpFlickr_auth_redirect']);
  	}
  	
    if (empty($_GET['frob'])) {
      $this->flickr->f->auth($permissions, true);
    } else {
      $this->flickr->f->auth_getToken($_GET['frob']);
    }
    
    if (empty($redirect)) {
  		header("Location: " . $default_redirect);
    } else {
	  	header("Location: " . $redirect);
    }
  	
	}
	
	private function getAllAlbums()
	{
    
    $albums = $this->flickr->f->photosets_getList($this->config->item('flickr_user_id'));
    return $albums;
    
	}
	
	public function import_albums()
	{
    
    $frob           = $this->flickr->f->auth();
    $token          = $this->flickr->f->auth_checkToken();  
    $albums         = $this->getAllAlbums();
    $newAlbums      = 0;
    $updatedAlbums  = 0;
    $deletedAlbums  = 0;
    $msg            = "";
    
    if ($albums) {
      
      foreach ($albums['photoset'] as $album) {
        
        $payload = array("id"           => $album['id'],
                         "title"        => $album['title'],
                         "description"  => $album['description'],
                         "primary"      => $album['primary'],
                         "photos"       => $album['photos'],
                         "date_create"  => $album['date_create'],
                         "date_update"  => $album['date_update']
                        );
        echo "<pre>"; print_r($album); echo "</pre>";
        
        echo "<pre>"; print_r($payload); echo "</pre>";
        
        // check if album exists in database
        $albumExists = $this->gpdb->getAlbumByID($album['id']);
        
        echo "<pre>"; print_r($albumExists); echo "</pre>";
        
        // if no records come back
        if (!$albumExists) {
          // insert album into database
          $this->gpdb->insertIntoDB($payload, "albums");  
          $newAlbums++;
        } else {
          // check if up-to-date
          if ($album['date_update'] > $albumExists->date_update) {
            // update record
            $this->gpdb->insertIntoDB($payload, "albums", $album['id']);
            $updatedAlbums++;
          }
        }
        
        exit;
        
        // get all photos in this album
{'fraction_non_alphanumeric': 0.16173120728929385, 'fraction_numerical': 0.003416856492027335, 'mean_word_length': 2.017611683848797, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 99, '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': '909271', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2115, 'n_words': 411}