Created
June 22, 2011 20:31
-
-
Save jessegreathouse/1041080 to your computer and use it in GitHub Desktop.
This is a class for one-time-engineering to reformat our login database to the new rendition. I needed to run this before I created the migration classes, otherwise there would be no data in the migration. I shouldn't need this engineering again but JUST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace CollegeDegrees\EdudirectBundle\Command\Util; | |
use CollegeDegrees\EdudirectBundle\Entity\Host; | |
use CollegeDegrees\EdudirectBundle\Entity\Login; | |
use CollegeDegrees\EdudirectBundle\Entity\Publishers; | |
use Doctrine\ORM\Query; | |
use Symfony\Component\Yaml\Yaml; | |
class SyncHosts extends AbstractSync | |
{ | |
private $types = array( | |
'wordpress' => 'admin', | |
'ftp' => 'ftp', | |
'cp' => 'cp', | |
'plesk' => 'plesk', | |
'clicky' => 'clicky', | |
'analytics' => 'analytics', | |
); | |
private $mapping = array( | |
'Id' => 'Username', | |
'Username' => 'Username', | |
'Password' => 'Password', | |
'Key' => 'Password', | |
'Url' => 'Url', | |
'Domain' => 'Domain', | |
'UsernameField' => 'UsernameField', | |
'PasswordField' => 'PasswordField', | |
'DomainField' => 'DomainField', | |
); | |
public function execute() | |
{ | |
$em = $this->getEntityManager(); | |
$query = $em->createQuery('select p from CollegeDegrees\EdudirectBundle\Entity\Publisher p'); | |
$publishers = $query->getResult(); | |
$result = Yaml::parse(__DIR__.'/Host/host.yml'); | |
foreach($result as $row) { | |
$host = new Host; | |
foreach ($row as $key => $val) { | |
$host->{'set'.ucwords($key)}($val); | |
} | |
$this->syncLogin($host, $publishers, $em); | |
} | |
} | |
protected function syncLogin($host, $publishers, $em) | |
{ | |
//Current YAML mapping | |
#id: 1 | |
#domain: **************.com | |
#analyticsId: ******** | |
#clickyId: ******* | |
#clickyKey: ********** | |
#adminUrl: | |
#adminUsername: | |
#adminPassword: "" | |
#adminRedirect: wp-admin/ | |
#adminUsernameField: log | |
#adminPasswordField: pwd | |
#adminRedirectField: redirect_to | |
#ftpUrl: ******** | |
#ftpUsername: ********* | |
#ftpPassword: ******* | |
#ftpOrSsh: SSH | |
#cpUrl: https://**********.com/ | |
#cpDomain: | |
#cpUsername: *********** | |
#cpPassword: ************** | |
#cpDomainField: | |
#cpUsernameField: | |
#cpPasswordField: | |
#pleskUrl: | |
#pleskUsername: | |
#pleskPassword: | |
foreach ($this->types as $name => $type) { | |
$login = new Login; | |
foreach ($this->mapping as $key => $value) { | |
$method = 'get'.ucwords($type).$key; | |
if (is_callable(array($host, $method)) && (null !== ($data = $host->{$method}()))) { | |
$login->{'set'.$value}($data); | |
unset($data); | |
} | |
} | |
if ($type == 'ftp') { | |
$name = (strtoupper($host->getFtpOrSsh()) == 'SSH') ? 'ssh' : 'ftp'; | |
} | |
$login->setName($name); | |
$login->setDomain($host->getDomain()); | |
foreach ($publishers as $publisher) { | |
if (false !== strpos(strtolower($publisher->getName()), strtolower($host->getDomain()))) { | |
echo "--found publisher match--\n"; | |
echo "publisher: " .$publisher->getName() . " | domain: ". strtolower($host->getDomain()) ."\n\n"; | |
$login->setPublisher($publisher); | |
} | |
} | |
$em->persist($login); | |
$em->flush(); | |
unset($login); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment